random generator seed

Michel Arboi <[email protected]> Fri, 17 Jun 2005 10:53:31 +0200
Newsgroups gmane.comp.security.nessus.devel
Message-ID <[email protected]>
I was a little paranoid and thought that this patch might be better
than the current code. What do you thing?

_______________________________________________
Nessus-devel mailing list
[email protected]
http://mail.nessus.org/mailman/listinfo/nessus-devel
(unnamed) (text/x-patch, 1.7 KB)
--- libnasl/nasl/exec.c	29 Apr 2005 08:52:48 -0000	1.81
+++ libnasl/nasl/exec.c	17 Jun 2005 08:48:14 -0000
@@ -1729,7 +1729,11 @@
   unsigned int cached_script_len = 0;
 #endif
   
+#if 0
   srand48(getpid() + getppid() + (long)time(NULL));
+#else
+  nessus_init_random();  /* Be paranoid */
+#endif
 
   old_dir[sizeof(old_dir) - 1] = '\0';
   getcwd(old_dir, sizeof(old_dir) - 1);
--- nessus-core/nessusd/processes.c	14 Mar 2005 10:01:54 -0000	1.9
+++ nessus-core/nessusd/processes.c	17 Jun 2005 08:48:15 -0000
@@ -78,7 +78,7 @@
   void * argument;
 {
  int pid;
-
+ int	myrand = lrand48();
  
 
  pid = fork();
@@ -94,7 +94,8 @@
   nessus_signal(SIGUSR2, SIG_IGN);
   nessus_signal(SIGCHLD, sighand_chld);
   nessus_signal(SIGSEGV, sighand_segv);	/* Comment this line out to dump a core and debug nessusd */
-  srand48(getpid() + getppid() + (long)time(NULL));
+  /* Desynchronize random generator from father - this should be enough */
+  srand48(myrand);
   (*function)(argument);
   EXIT(0);
  }
--- nessus-libraries/libnessus/plugutils.c	16 Jun 2005 19:10:59 -0000	1.135
+++ nessus-libraries/libnessus/plugutils.c	17 Jun 2005 08:48:16 -0000
@@ -1638,7 +1638,7 @@
  int upstream = 0;
  char * buf = NULL;
  int bufsz = 0;
- 
+ int		myrand = lrand48();
  
  if ( type != NULL )
 	*type = -1;
@@ -1675,6 +1675,7 @@
  while( res != NULL )
  {
   pid_t pid;
+  myrand += lrand48();
   socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair);
   if ( (pid = fork()) == 0 )
   {
@@ -1698,7 +1699,8 @@
     if ( to != NULL )  tictac = atoi(to);
    }
 
-   srand48(getpid() + getppid() + time(NULL));
+   /* Desynchronize random generator from father - this should be enough */
+   srand48(myrand);
  
    sig_term(_exit);
    sig_alarm(_exit);