The branch, master has been updated via d242129 echo_srv: Improve reopening low fds. via 32c9508 echo_srv: Don't leak client_sock on failures in echo_tcp via 4ed4524 tests: Fix an out of bound access. via fab60bb tests: Fix a possible resource leak on error in sockopt test. via efd810d swrap: Do not leak memory in swrap_recvmsg_after(). via 3786fdc echo_srv: Fix resource leak of fd in pidfile(). via f165d65 echo_srv: Fix resource leak of s2 on error. via 2254633 echo_srv: Fix resource leak of sock. via 03726df tests: Fix creating remove_cmd. via 2fb2458 tests: Don't leak file description in test_ioctl. via d5a37e5 cmake: Only set policy in cmake 3.0. from af3c688 cmake: Fix configure warning with cmake 3.0.
http://gitweb.samba.org/?p=socket_wrapper.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit d242129438adb6560f9c31383981cad46588bd90 Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 11:54:03 2014 +0200 echo_srv: Improve reopening low fds. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit 32c9508b13218d4594c9991d218c93eff1545c86 Author: Jakub Hrozek <jhro...@redhat.com> Date: Thu Apr 10 11:41:31 2014 +0200 echo_srv: Don't leak client_sock on failures in echo_tcp Signed-off-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: Simo Sorce <i...@samba.org> commit 4ed4524c5851bbb042caa052f66263b734cf5546 Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 10:49:01 2014 +0200 tests: Fix an out of bound access. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit fab60bb3f61c7dfd1f028a1f9821dab9ad826df7 Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 10:46:18 2014 +0200 tests: Fix a possible resource leak on error in sockopt test. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit efd810d5e12e7b1409542874f5bf29ab0d431a7b Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 10:42:51 2014 +0200 swrap: Do not leak memory in swrap_recvmsg_after(). Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit 3786fdc51b18b74411a4d5cca9af2aa3ff250505 Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 10:40:32 2014 +0200 echo_srv: Fix resource leak of fd in pidfile(). Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit f165d65e82eaaf139a89cd8b3f58fbe60f8cbecd Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 10:30:40 2014 +0200 echo_srv: Fix resource leak of s2 on error. Found by Coverity. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit 2254633003312b1f7462a408480483a2ec58d18a Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 10:28:46 2014 +0200 echo_srv: Fix resource leak of sock. Found by Coverity. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit 03726df0861c1a4f85e938a77616ac8780aa4760 Author: Andreas Schneider <a...@samba.org> Date: Thu Apr 10 10:23:14 2014 +0200 tests: Fix creating remove_cmd. Found by Coverity. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit 2fb245848b786cd8a3d776810f1faf27d8819097 Author: Andreas Schneider <a...@samba.org> Date: Tue Apr 8 09:34:43 2014 +0200 tests: Don't leak file description in test_ioctl. Found by Coverity. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> Reviewed-by: Simo Sorce <i...@samba.org> commit d5a37e5661d6dd466cd5dd914300f06406b48f3d Author: Andreas Schneider <a...@samba.org> Date: Tue Apr 8 09:34:11 2014 +0200 cmake: Only set policy in cmake 3.0. Signed-off-by: Andreas Schneider <a...@samba.org> Reviewed-by: Jakub Hrozek <jhro...@redhat.com> ----------------------------------------------------------------------- Summary of changes: src/CMakeLists.txt | 4 ++- src/socket_wrapper.c | 7 ++-- tests/echo_srv.c | 56 ++++++++++++++++++++++----------- tests/test_echo_tcp_socket_options.c | 4 +- tests/test_echo_tcp_writev_readv.c | 6 ++- tests/test_ioctl.c | 7 +++- 6 files changed, 55 insertions(+), 29 deletions(-) Changeset truncated at 500 lines: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 449ed54..50ac9ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,8 @@ set_target_properties( ) # This needs to be at the end -cmake_policy(SET CMP0026 OLD) +if (CMAKE_VERSION VERSION_GREATER 2.8.13) + cmake_policy(SET CMP0026 OLD) +endif() get_target_property(SWRAP_LOCATION socket_wrapper LOCATION) set(SOCKET_WRAPPER_LOCATION ${SWRAP_LOCATION} PARENT_SCOPE) diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index c5b1fdf..5ed9d9f 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -3155,7 +3155,7 @@ static int swrap_recvmsg_after(int fd, { int saved_errno = errno; size_t i; - uint8_t *buf; + uint8_t *buf = NULL; off_t ofs = 0; size_t avail = 0; size_t remain; @@ -3187,7 +3187,7 @@ static int swrap_recvmsg_after(int fd, /* we capture it as one single packet */ buf = (uint8_t *)malloc(remain); - if (!buf) { + if (buf == NULL) { /* we just not capture the packet */ errno = saved_errno; return -1; @@ -3228,7 +3228,7 @@ static int swrap_recvmsg_after(int fd, msg->msg_name, &msg->msg_namelen); if (rc == -1) { - return -1; + goto done; } swrap_dump_packet(si, @@ -3247,6 +3247,7 @@ static int swrap_recvmsg_after(int fd, break; } +done: free(buf); errno = saved_errno; return 0; diff --git a/tests/echo_srv.c b/tests/echo_srv.c index 70d9a84..9102a87 100644 --- a/tests/echo_srv.c +++ b/tests/echo_srv.c @@ -53,7 +53,9 @@ static int pidfile(const char *path) { int err; int fd; - char pid_str[32]; + char pid_str[32] = { 0 }; + ssize_t nwritten; + size_t len; fd = open(path, O_RDONLY, 0644); err = errno; @@ -70,9 +72,14 @@ static int pidfile(const char *path) return err; } - memset(pid_str, 0, sizeof(pid_str)); snprintf(pid_str, sizeof(pid_str) -1, "%u\n", (unsigned int) getpid()); - write(fd, pid_str, strlen(pid_str)); + len = strlen(pid_str); + + nwritten = write(fd, pid_str, len); + close(fd); + if (nwritten != (ssize_t)len) { + return EIO; + } return 0; } @@ -82,6 +89,7 @@ static int become_daemon(struct echo_srv_opts *opts) int ret; pid_t child_pid; int fd; + int i; if (getppid() == 1) { return 0; @@ -119,14 +127,22 @@ static int become_daemon(struct echo_srv_opts *opts) close(fd); } - fd = open("/dev/null", O_RDWR); - if (fd == -1) { - ret = errno; - perror("open"); - return ret; + for (i = 0; i < 3; i++) { + fd = open("/dev/null", O_RDWR, 0); + if (fd < 0) { + fd = open("/dev/null", O_WRONLY, 0); + } + if (fd < 0) { + ret = errno; + perror("Can't open /dev/null"); + return ret; + } + if (fd != i) { + perror("Didn't get correct fd"); + close(fd); + return EINVAL; + } } - dup(fd); - dup(fd); umask(0177); return 0; @@ -182,6 +198,7 @@ static int setup_srv(struct echo_srv_opts *opts, int *_sock) ret = listen(sock, BACKLOG); if (ret == -1) { ret = errno; + close(sock); perror("listen"); return ret; } @@ -306,11 +323,11 @@ static int socket_dup(int s) /* Test dup2 */ s = dup2(s2, s); + close(s2); if (s == -1) { perror("dup"); return -1; } - close(s2); ZERO_STRUCT(srv_ss3); srv_ss3_len = sizeof(srv_ss3); @@ -387,41 +404,42 @@ static void echo_tcp(int sock) char buf[BUFSIZE]; ssize_t bret; - int client_sock; + int client_sock = -1; int s; s = accept(sock, (struct sockaddr *)&css, &addrlen); if (s == -1) { perror("accept"); - return; + goto done; } client_sock = socket_dup(s); if (client_sock == -1) { perror("socket_dup"); - return; + goto done; } /* Start ping pong */ while (1) { bret = recv(client_sock, buf, BUFSIZE, 0); if (bret == -1) { - close(client_sock); perror("recv"); - continue; + goto done; } else if (bret == 0) { break; } bret = send(client_sock, buf, bret, 0); if (bret == -1) { - close(client_sock); perror("send"); - continue; + goto done; } } - close(client_sock); +done: + if (client_sock != -1) { + close(client_sock); + } } static void echo_udp(int sock) diff --git a/tests/test_echo_tcp_socket_options.c b/tests/test_echo_tcp_socket_options.c index 8ec631f..49b1187 100644 --- a/tests/test_echo_tcp_socket_options.c +++ b/tests/test_echo_tcp_socket_options.c @@ -118,7 +118,6 @@ static void test_bind_ipv6_only(void **state) case AF_INET: assert_int_equal(rc, -1); - close(s); break; case AF_INET6: assert_int_equal(rc, 0); @@ -126,11 +125,12 @@ static void test_bind_ipv6_only(void **state) rc = bind(s, ri->ai_addr, ri->ai_addrlen); assert_int_equal(rc, 0); - close(s); break; default: break; } + + close(s); } freeaddrinfo(res); } diff --git a/tests/test_echo_tcp_writev_readv.c b/tests/test_echo_tcp_writev_readv.c index 9f6703f..c7b8dd9 100644 --- a/tests/test_echo_tcp_writev_readv.c +++ b/tests/test_echo_tcp_writev_readv.c @@ -68,7 +68,8 @@ static void test_writev_readv_ipv4(void **state) for (j = 0; j < i; j++) { memset(send_buf[j], 0, 64); - snprintf(send_buf[j], sizeof(send_buf), "packet.%d", j); + snprintf(send_buf[j], sizeof(send_buf[j]), + "packet.%d", j); iov_send[j].iov_base = send_buf[j]; iov_send[j].iov_len = strlen(send_buf[j]); @@ -132,7 +133,8 @@ static void test_writev_readv_ipv6(void **state) for (j = 0; j < i; j++) { memset(send_buf[j], 0, 64); - snprintf(send_buf[j], sizeof(send_buf), "packet.%d", j); + snprintf(send_buf[j], sizeof(send_buf[j]), + "packet.%d", j); iov_send[j].iov_base = send_buf[j]; iov_send[j].iov_len = strlen(send_buf[j]); diff --git a/tests/test_ioctl.c b/tests/test_ioctl.c index d365641..077e553 100644 --- a/tests/test_ioctl.c +++ b/tests/test_ioctl.c @@ -37,9 +37,10 @@ static void teardown(void **state) (void) state; /* unused */ - if (swrap_dir != NULL) { - snprintf(remove_cmd, sizeof(remove_cmd), "rm -rf %s", swrap_dir); + if (swrap_dir == NULL) { + return; } + snprintf(remove_cmd, sizeof(remove_cmd), "rm -rf %s", swrap_dir); rc = system(remove_cmd); if (rc < 0) { @@ -85,6 +86,8 @@ static void test_swrap_ioctl_sock(void **state) assert_int_not_equal(grp, -127); #endif + + close(fd); } int main(void) { -- Socket Wrapper Repository