Skip to contentSkip to conversation

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

PATCH Jim Meyering 2 participants 3 messages Jun 15, 2007 – Jun 16, 2007

lore
Share & tools
lore
#0 lore raw

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

lib/uuid/ChangeLog +5 -0
diff -r 11b6e3e021f0 -r 777972a573b3 lib/uuid/ChangeLog
@@ -1,3 +1,8 @@ 2006-10-22  Theodore Tso  <[email protected]
+2007-06-15  Jim Meyering  <[email protected]>
+
+	* gen_uuid.c (get_random_bytes): Don't leave /dev/urandom open.
+	(uuid_generate): Likewise.
+
 2006-10-22  Theodore Tso  <[email protected]>
 
 	* gen_uuid.c (get_random_bytes): Add in randomness based on
lib/uuid/gen_uuid.c +5 -2
diff -r 11b6e3e021f0 -r 777972a573b3 lib/uuid/gen_uuid.c
@@ -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);
 }
#1 lore raw
Quoted 1 line · Jim Meyering

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

Is there a reason why the caching of the open file descriptor for /dev/random is causing you problems? Keeping it open was deliberate.

Regards,

- Ted

#2 lore raw
Quoted 5 lines · Theodore Tso
Quoted 1 line · Jim Meyering

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

Is there a reason why the caching of the open file descriptor for /dev/random is causing you problems? Keeping it open was deliberate.

I saw it open at exit, missed the 'static' and thought it was an fd leak. Désolé.