As a developer on the PurifyPlus product at IBM, I'd like to contribute a 
Purify usage note to this discussion.

I see that the issue is RAND_add using whatever memory it's given (some of 
which can be uninitialized garbage) as entropy input for the random number 
generator. Tools like Purify report a violation when RAND_add uses 
uninitialized areas of the block. The proposed change that started this 
thread was to pre-initialize a stat buffer before calling stat() and then 
passing it to RAND_add.

Instead of changing all the callers of RAND_add to carefully 
pre-initialize the memory they pass, it seems like it would be better to 
change RAND_add itself and leave the callers alone. I see two possible 
ways to change RAND_add to prevent these memory usage error reports. One 
is easy and the other is hard and has limitations.

EASY FIX: wherever RAND_add is defined (macro? function?), give it a 
different body for -DPURIFY builds. When PURIFY is defined, don't use the 
memory being passed in at all. This sounds extreme, but it should work. 
Sure, the entropy factors will change and the resulting numbers might not 
be very random, but who cares? Builds with -DPURIFY are about testing the 
memory usage of the app or library, not about the quality of its random 
numbers, right? This solution has the virtue of working for both Purify 
and Valgrind, and you don't have to hunt down and tweak every caller of 
RAND_add. (It would probably be good to ensure there is *some* entropy 
when PURIFY is defined, so the numbers you get aren't the same every 
time.)

I was going to describe the harder fix here, involving the Purify API. But 
I've decided not to: It's a little tricky, involves changing both source 
code and makefiles, only applies to Purify, and has other quirks. Much too 
ugly compared to the EASY FIX above. If somebody wants to hear the whole 
story they can ask me.

I'm not sure how the OpenSSL build is structured. The "easy fix" idea 
works if RAND_add gets rebuilt when you set -DPURIFY. If its callers get 
rebuilt but RAND_add does not, then you will have to hunt down and tweak 
all the callers after all.

Thanks for using Purify!

-- Allan Pratt, [email protected]
Rational software division of IBM

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [email protected]

Reply via email to