Whamcloud - gitweb
libuuid: Make sure fd's 0, 1, and 2 are valid before exec'ing uuidd
authorTheodore Ts'o <tytso@mit.edu>
Mon, 29 Jun 2009 23:06:45 +0000 (19:06 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 29 Jun 2009 23:06:45 +0000 (19:06 -0400)
When closing all of the file descriptors before starting uuidd, make
sure file descriptors 0, 1, and 2 are reserved by opening /dev/null.
This prevents strange bugs caused by assumptions regarding file
descriptors <= 2 as being special.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/uuid/gen_uuid.c

index b7a12ee..aa313ef 100644 (file)
@@ -455,8 +455,11 @@ static void close_all_fds(void)
        max = OPEN_MAX;
 #endif
 
-       for (i=0; i < max; i++)
+       for (i=0; i < max; i++) {
                close(i);
+               if (i <= 2)
+                       open("/dev/null", O_RDWR);
+       }
 }