diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-21 19:00:33 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-21 19:22:07 -0800 |
| commit | d571d3f03bf56be2a5828fe2db86308229dc5625 (patch) | |
| tree | a04ec11ee3c5d28a061fae2151669ad17e46915a /src | |
| parent | ebc020cd4f8e2121d6ecc2dfc0cd48c594329cde (diff) | |
| download | nng-d571d3f03bf56be2a5828fe2db86308229dc5625.tar.gz nng-d571d3f03bf56be2a5828fe2db86308229dc5625.tar.bz2 nng-d571d3f03bf56be2a5828fe2db86308229dc5625.zip | |
posix udp: More explicit checks for bogus address family
This triggered an error on FreeBSD because apparently FreeBSD will
return a different value when seeing an AF_UNIX socket with UDP.
Diffstat (limited to 'src')
| -rw-r--r-- | src/platform/posix/posix_udp.c | 11 | ||||
| -rw-r--r-- | src/platform/udp_test.c | 1 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c index 1e2f6df9..667fbaec 100644 --- a/src/platform/posix/posix_udp.c +++ b/src/platform/posix/posix_udp.c @@ -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) { diff --git a/src/platform/udp_test.c b/src/platform/udp_test.c index 7cafff1e..211c985c 100644 --- a/src/platform/udp_test.c +++ b/src/platform/udp_test.c @@ -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); |
