"sizeof(sun->sun_path)" is not always the same as "sizeof(addr->u.sockname)"

on all platforms;

because of that BUILD_ASSERT was failing on macOS.

(on macOS "sizeof(sun->sun_path) == 104" and
"sizeof(addr->u.sockname) == 108")

[ Linux man page says it can be as small as 92, so let's use the real value.
  I also cleaned up the incorrect comment order on that struct! --RR ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Isidoro Ghezzi 2018-05-09 09:34:02 +09:30 committed by Rusty Russell
parent c33bbb2639
commit 855d0b9401
2 changed files with 5 additions and 5 deletions

View File

@ -8,9 +8,7 @@
#include <common/wireaddr.h> #include <common/wireaddr.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/un.h>
#include <wire/wire.h> #include <wire/wire.h>
/* Returns false if we didn't parse it, and *cursor == NULL if malformed. */ /* Returns false if we didn't parse it, and *cursor == NULL if malformed. */

View File

@ -5,6 +5,8 @@
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
struct in6_addr; struct in6_addr;
struct in_addr; struct in_addr;
@ -87,12 +89,12 @@ enum wireaddr_internal_type {
struct wireaddr_internal { struct wireaddr_internal {
enum wireaddr_internal_type itype; enum wireaddr_internal_type itype;
union { union {
/* ADDR_INTERNAL_SOCKNAME */ /* ADDR_INTERNAL_WIREADDR */
struct wireaddr wireaddr; struct wireaddr wireaddr;
/* ADDR_INTERNAL_ALLPROTO */ /* ADDR_INTERNAL_ALLPROTO */
u16 port; u16 port;
/* ADDR_INTERNAL_WIREADDR */ /* ADDR_INTERNAL_SOCKNAME */
char sockname[108]; char sockname[sizeof(((struct sockaddr_un *)0)->sun_path)];
} u; } u;
}; };
bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr, u16 port, bool wildcard_ok, const char **err_msg); bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr, u16 port, bool wildcard_ok, const char **err_msg);