]> Savannah Git Hosting - gnulib.git/commitdiff
af_alg: don’t leak file descriptors into children
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 May 2018 18:34:28 +0000 (11:34 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 May 2018 18:34:46 +0000 (11:34 -0700)
* lib/af_alg.c (alg_socket): Use SOCK_CLOEXEC when creating sockets.
This code should be compiled only on recent GNU/Linux platforms
so we shouldn’t have to also depend on the accept4 module.

ChangeLog
lib/af_alg.c

index c4e155392fac4a8ffee8117039a0b7ede6f15302..818d3a6020ed72e35734d5b7b22ed02c223acc03 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2018-05-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       af_alg: don’t leak file descriptors into children
+       * lib/af_alg.c (alg_socket): Use SOCK_CLOEXEC when creating sockets.
+       This code should be compiled only on recent GNU/Linux platforms
+       so we shouldn’t have to also depend on the accept4 module.
+
        af_alg: coalesce socket creation
        * lib/af_alg.c (alg_socket): New function.
        (afalg_buffer, afalg_stream): Use it.  This avoids some
index ca3dd032355da4799321d81925fd9a5dbaaebb38..c85140a33587d938a5e690d0ddfdb189588167da 100644 (file)
@@ -49,11 +49,11 @@ alg_socket (char const *alg)
     if (i == sizeof salg.salg_name - 1)
       return -EINVAL;
 
-  int cfd = socket (AF_ALG, SOCK_SEQPACKET, 0);
+  int cfd = socket (AF_ALG, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
   if (cfd < 0)
     return -EAFNOSUPPORT;
   int ofd = (bind (cfd, (struct sockaddr *) &salg, sizeof salg) == 0
-             ? accept (cfd, NULL, 0)
+             ? accept4 (cfd, NULL, 0, SOCK_CLOEXEC)
              : -1);
   close (cfd);
   return ofd < 0 ? -EAFNOSUPPORT : ofd;