From 94137885710fe276454f933f9cbfefbe02ead347 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Tue, 26 Jan 2010 18:08:42 +0000 Subject: [PATCH] PR: 2138 Submitted by: Kevin Regan Clear stat structure if -DPURIFY is set to avoid problems on some platforms which include unitialised fields. --- crypto/rand/randfile.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c index e12fe0b90c..84276d7d46 100644 --- a/crypto/rand/randfile.c +++ b/crypto/rand/randfile.c @@ -117,6 +117,15 @@ int RAND_load_file(const char *file, long bytes) if (file == NULL) return(0); +#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); if (bytes == 0) return(ret); -- 2.25.1