]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: close unused peer socket in the tests using socketpair
authorDaiki Ueno <ueno@gnu.org>
Sun, 5 Mar 2023 06:20:35 +0000 (15:20 +0900)
committerDaiki Ueno <ueno@gnu.org>
Thu, 9 Mar 2023 12:17:06 +0000 (21:17 +0900)
Otherwise, the subsequent call to wait will block, when the child
process exits abnormally.  Checked with the following script:

  for i in $(git grep -l socketpair); do
          if ! grep -q 'close.*\[' $i; then echo $i; fi
  done

Signed-off-by: Daiki Ueno <ueno@gnu.org>
tests/anonself.c
tests/cipher-alignment.c
tests/client-sign-md5-rep.c
tests/dhepskself.c
tests/dhex509self.c
tests/duplicate-extensions.c
tests/naked-alerts.c
tests/server-sign-md5-rep.c
tests/srp.c
tests/tls-session-supplemental.c

index b92cb286a186e925182d9fe4096bfbcfa24ad99b..f33f563ea261f609dd88659f99edeb977a3a2e64 100644 (file)
@@ -275,10 +275,12 @@ void start(const char *name, const char *prio)
        if (child) {
                int status;
                /* parent */
+               close(sockets[1]);
                server(sockets[0], prio);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[0]);
                client(sockets[1], prio);
                exit(0);
        }
index ae6aa782b029b1f18003213f833d4515b17479b3..65fa6e0fa78435801c9cd6a17644e90ac3adfe6d 100644 (file)
@@ -491,10 +491,12 @@ void start(const char *prio)
        if (child) {
                int status;
 
+               close(sockets[1]);
                server(sockets[0], prio);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[0]);
                client(sockets[1], prio);
                exit(0);
        }
index 7b573aa4fcdeeb3e47c6562ea057c11beddd386a..08866c838c8752d679ff2fa24548802755cbb42e 100644 (file)
@@ -809,10 +809,12 @@ void doit(void)
        if (child) {
                int status;
 
+               close(sockets[0]);
                client(sockets[1]);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[1]);
                server(sockets[0]);
                _exit(0);
        }
index f3eebc0c9c817c150a7e96a3ab43dad2d83ef967..a7caa383817c5905efd0ea77200a4be6abf951d6 100644 (file)
@@ -295,10 +295,12 @@ void doit(void)
        if (child) {
                int status;
                /* parent */
+               close(sockets[1]);
                server(sockets[0]);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[0]);
                client(sockets[1]);
                exit(0);
        }
index b969ba8a1330533538bd0a064c4b0bc1e56108d4..548a97ba11964ff6b2436e154fa7173dd01a6699 100644 (file)
@@ -383,10 +383,12 @@ void doit(void)
        if (child) {
                int status;
 
+               close(sockets[1]);
                server(sockets[0]);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[0]);
                client(sockets[1]);
                exit(0);
        }
index 5384eaa227a149f8e733b2b2203d8c51379c3b74..54a4a7bb15b45f11217b2c4c26b5d47be1b55bec 100644 (file)
@@ -214,10 +214,12 @@ void doit(void)
        if (child) {
                int status;
 
+               close(sockets[0]);
                client(sockets[1]);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[1]);
                server(sockets[0]);
                _exit(0);
        }
index aded2932f5433cb2351698896cbb7d4389edbd91..73331f72fc0588f1eebbc0d4a6643eac5961668c 100644 (file)
@@ -163,10 +163,12 @@ void doit(void)
        if (child) {
                int status;
 
+               close(sockets[1]);
                server(sockets[0]);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[0]);
                client(sockets[1]);
                exit(0);
        }
index b3afd9db717b4c3e5030362f54a8bb3da1189521..c7f31c9e63c43ac571a88083f29e7a014d18a26b 100644 (file)
@@ -239,10 +239,12 @@ void doit(void)
        if (child) {
                int status;
 
+               close(sockets[0]);
                client(sockets[1]);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[1]);
                server(sockets[0]);
                _exit(0);
        }
index 0cd9d2d09e2448998457f335b416d962ef65acad..1fc582c90114df1605f1b6a739a20a2f70b4cb82 100644 (file)
@@ -293,6 +293,7 @@ static void start(const char *name, const char *prio, const char *user,
        if (child) {
                int status;
                /* parent */
+               close(fd[0]);
                client(fd[1], prio, user, pass, exp_err);
                if (exp_err < 0) {
                        kill(child, SIGTERM);
@@ -302,6 +303,7 @@ static void start(const char *name, const char *prio, const char *user,
                        check_wait_status(status);
                }
        } else {
+               close(fd[1]);
                server(fd[0], prio);
                exit(0);
        }
index 65a9c95c376d9bd4c351c1b55663e4de6fddf1d9..e71780c457f88e0394d31db8b350de32b528fda3 100644 (file)
@@ -291,10 +291,12 @@ void start(const char *prio, unsigned server_only)
        if (child) {
                int status;
                /* parent */
+               close(sockets[1]);
                server(sockets[0], prio, server_only);
                wait(&status);
                check_wait_status(status);
        } else {
+               close(sockets[0]);
                client(sockets[1], prio, server_only);
                exit(0);
        }