close /dev/urandom fd (e2fsprogs 1.40-WIP (7-Apr-2007))

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The file descriptor opened on /dev/urandom can be closed sooner:

diff -r 11b6e3e021f0 -r 777972a573b3 lib/uuid/ChangeLog
--- a/lib/uuid/ChangeLog	Thu May 31 12:39:02 2007 -0400
+++ b/lib/uuid/ChangeLog	Fri Jun 15 18:05:09 2007 +0200
@@ -1,3 +1,8 @@ 2006-10-22  Theodore Tso  <tytso@xxxxxxx
+2007-06-15  Jim Meyering  <jim@xxxxxxxxxxxx>
+
+	* gen_uuid.c (get_random_bytes): Don't leave /dev/urandom open.
+	(uuid_generate): Likewise.
+
 2006-10-22  Theodore Tso  <tytso@xxxxxxx>
 
 	* gen_uuid.c (get_random_bytes): Add in randomness based on
diff -r 11b6e3e021f0 -r 777972a573b3 lib/uuid/gen_uuid.c
--- a/lib/uuid/gen_uuid.c	Thu May 31 12:39:02 2007 -0400
+++ b/lib/uuid/gen_uuid.c	Fri Jun 15 18:05:09 2007 +0200
@@ -139,6 +139,7 @@ static void get_random_bytes(void *buf, 
 			cp += i;
 			lose_counter = 0;
 		}
+		close(fd);
 	}
 	
 	/*
@@ -337,8 +338,10 @@ void uuid_generate_random(uuid_t out)
  */
 void uuid_generate(uuid_t out)
 {
-	if (get_random_fd() >= 0)
+	int fd;
+	if ((fd = get_random_fd()) >= 0) {
+		close(fd);
 		uuid_generate_random(out);
-	else
+	} else
 		uuid_generate_time(out);
 }

Signed-off-by: Jim Meyering <jim@xxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux