[Openvas-commits] r9527 - in trunk/openvas-libraries: . misc

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 26 09:55:09 CET 2010


Author: mwiegand
Date: 2010-11-26 09:55:09 +0100 (Fri, 26 Nov 2010)
New Revision: 9527

Modified:
   trunk/openvas-libraries/ChangeLog
   trunk/openvas-libraries/misc/rand.c
Log:
* misc/rand.c (openvas_init_random): Check return values of calls to
  fread () and fclose () and log a warning if something seems wrong with
  /dev/urandom.


Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog	2010-11-26 08:44:24 UTC (rev 9526)
+++ trunk/openvas-libraries/ChangeLog	2010-11-26 08:55:09 UTC (rev 9527)
@@ -1,5 +1,11 @@
 2010-11-26  Michael Wiegand <michael.wiegand at greenbone.net>
 
+	* misc/rand.c (openvas_init_random): Check return values of calls to
+	fread () and fclose () and log a warning if something seems wrong with
+	/dev/urandom.
+
+2010-11-26  Michael Wiegand <michael.wiegand at greenbone.net>
+
 	* misc/openvas_ssh_login.c (openvas_ssh_login_file_write): Check
 	return value and return FALSE if the call to write () failed.
 

Modified: trunk/openvas-libraries/misc/rand.c
===================================================================
--- trunk/openvas-libraries/misc/rand.c	2010-11-26 08:44:24 UTC (rev 9526)
+++ trunk/openvas-libraries/misc/rand.c	2010-11-26 08:55:09 UTC (rev 9527)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
+#include <glib.h>
 
 
 /**
@@ -38,8 +39,10 @@
 
   if ((fp = fopen ("/dev/urandom", "r")) != NULL)
     {
-      (void) fread (&x, sizeof (x), 1, fp);
-      fclose (fp);
+      if (fread (&x, sizeof (x), 1, fp) != 1)
+        g_warning ("%s: failed to read from /dev/urandom", __FUNCTION__);
+      if (fclose (fp) != 0)
+        g_warning ("%s: failed to close /dev/urandom", __FUNCTION__);
     }
   x += time (NULL) + getpid () + getppid ();
   srand48 (x);



More information about the Openvas-commits mailing list