PR: 2138
authorDr. Stephen Henson <steve@openssl.org>
Tue, 26 Jan 2010 18:07:41 +0000 (18:07 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Tue, 26 Jan 2010 18:07:41 +0000 (18:07 +0000)
Submitted by: Kevin Regan <k.regan@f5.com>

Clear stat structure if -DPURIFY is set to avoid problems on some
platforms which include unitialised fields.

crypto/rand/randfile.c

index 7dc4ceae8e61207c16fddc842cd7b7e6f3c6ea4c..4ed40b7b70afb6438f7513755fef1fe15387636e 100644 (file)
@@ -118,6 +118,14 @@ int RAND_load_file(const char *file, long bytes)
        if (file == NULL) return(0);
 
 #ifndef OPENSSL_NO_POSIX_IO
+#ifdef PURIFY
+       /* struct stat can have padding and unused fields that may not be
+        * initialized in the call to stat(). We need to clear the entire
+        * structure before calling RAND_add() to avoid complaints from
+        * applications such as Valgrind.
+        */
+       memset(&sb, 0, sizeof(sb));
+#endif
        if (stat(file,&sb) < 0) return(0);
        RAND_add(&sb,sizeof(sb),0.0);
 #endif