Skip to content

Commit

Permalink
posix udp: More explicit checks for bogus address family
Browse files Browse the repository at this point in the history
This triggered an error on FreeBSD because apparently FreeBSD will
return a different value when seeing an AF_UNIX socket with UDP.
  • Loading branch information
gdamore committed Dec 22, 2024
1 parent ebc020c commit d571d3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/platform/posix/posix_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,18 @@ nni_plat_udp_open(nni_plat_udp **upp, nni_sockaddr *bindaddr)
struct sockaddr_storage sa;
int rv;

if ((salen = nni_posix_nn2sockaddr(&sa, bindaddr)) < 1) {
if (bindaddr == NULL) {
return (NNG_EADDRINVAL);
}
switch (bindaddr->s_family) {
case NNG_AF_INET:
case NNG_AF_INET6:
break;
default:
return (NNG_EADDRINVAL);
}
salen = nni_posix_nn2sockaddr(&sa, bindaddr);
NNI_ASSERT(salen > 1);

// UDP opens can actually run synchronously.
if ((udp = NNI_ALLOC_STRUCT(udp)) == NULL) {
Expand Down
1 change: 1 addition & 0 deletions src/platform/udp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ test_udp_bogus_bind(void)
// Some platforms reject IPC addresses altogether (Windows),
// whereas others just say it's not supported with UDP.
NUTS_ASSERT((rv == NNG_ENOTSUP) || (rv == NNG_EADDRINVAL));
NUTS_MSG("Result was %d %s", rv, nng_strerror(rv));

// NULL address also bad.
NUTS_FAIL(nng_udp_open(&u, NULL), NNG_EADDRINVAL);
Expand Down

0 comments on commit d571d3f

Please sign in to comment.