diff --git a/src/core/sockfd.c b/src/core/sockfd.c index 1b4dbc1d7..edf8e0c2d 100644 --- a/src/core/sockfd.c +++ b/src/core/sockfd.c @@ -137,8 +137,7 @@ sfd_listener_set_fd(void *arg, const void *buf, size_t sz, nni_type t) int fd; int rv; - if ((rv = nni_copyin_int(&fd, buf, sz, NNI_MININT, NNI_MAXINT, t)) != - 0) { + if ((rv = nni_copyin_int(&fd, buf, sz, 0, NNI_MAXINT, t)) != 0) { return (rv); } @@ -169,7 +168,7 @@ static int sfd_listener_get_addr(void *arg, void *buf, size_t *szp, nni_type t) { NNI_ARG_UNUSED(arg); - nng_sockaddr sa; + nng_sockaddr sa; sa.s_family = NNG_AF_UNSPEC; return (nni_copyout_sockaddr(&sa, buf, szp, t)); } @@ -181,7 +180,7 @@ static const nni_option sfd_listener_options[] = { }, { .o_name = NNG_OPT_LOCADDR, - .o_get = sfd_listener_get_addr, + .o_get = sfd_listener_get_addr, }, { .o_name = NULL, diff --git a/src/sp/transport/socket/sockfd_test.c b/src/sp/transport/socket/sockfd_test.c index c27f49bdf..de1f582b0 100644 --- a/src/sp/transport/socket/sockfd_test.c +++ b/src/sp/transport/socket/sockfd_test.c @@ -484,6 +484,22 @@ test_sfd_fd_option_type(void) #endif } +void +test_sfd_fd_invalid_fd(void) +{ +#ifdef NNG_HAVE_SOCKETPAIR + nng_socket s; + nng_listener l; + + NUTS_OPEN(s); + NUTS_PASS(nng_listener_create(&l, s, "socket://")); + NUTS_FAIL( + nng_listener_set_int(l, NNG_OPT_SOCKET_FD, -100), NNG_EINVAL); + NUTS_CLOSE(s); +#else + NUTS_SKIP("no socketpair"); +#endif +} void test_sfd_fd_dev_zero(void) { @@ -521,6 +537,7 @@ NUTS_TESTS = { { "socket pipe peer id", test_sockfd_pipe_peer }, { "socket listen full", test_sfd_listen_full }, { "socket bad fd type", test_sfd_fd_option_type }, + { "socket invalid fd", test_sfd_fd_invalid_fd }, { "socket dev zero", test_sfd_fd_dev_zero }, { NULL, NULL }, };