diff options
author | Rich Salz <rsalz@openssl.org> | 2017-07-26 14:27:30 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2017-07-26 19:27:54 -0400 |
commit | 9f08a1c63efa2205aca4361a830ac04407325597 (patch) | |
tree | a3ab9a036edf961cb6b09e5ed7f82919e6b456d5 /fuzz/test-corpus.c | |
parent | 43405889f47648ee70c1b412b8b71570e8aaa24a (diff) | |
download | openssl-new-9f08a1c63efa2205aca4361a830ac04407325597.tar.gz |
Install custom RAND_METHOD for fuzzing
Instead of setting a "magic" global variable to force RAND to keep
consistent state and always generate the same bytestream, have
the fuzzing code install its own RAND_METHOD that does this. For
BN_RAND_DEBUG, we just don't do it; that debugging was about mucking
with BN's internal representation, not requiring predictable rand
bytes.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/4025)
Diffstat (limited to 'fuzz/test-corpus.c')
-rw-r--r-- | fuzz/test-corpus.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/fuzz/test-corpus.c b/fuzz/test-corpus.c index 9cef01f86d..a876f209c9 100644 --- a/fuzz/test-corpus.c +++ b/fuzz/test-corpus.c @@ -18,8 +18,39 @@ #include <stdlib.h> #include <sys/stat.h> #include <openssl/crypto.h> +#include <openssl/rand.h> #include "fuzzer.h" +static int fuzz_bytes(unsigned char *buf, int num) +{ + unsigned char val = 1; + + while (--num >= 0) + *buf++ = val++; + return 1; +} + +static int fuzz_status(void) +{ + return 1; +} + +static RAND_METHOD fuzz_rand_method = { + NULL, + fuzz_bytes, + NULL, + NULL, + fuzz_bytes, + fuzz_status +}; + +void FuzzerSetRand(void) +{ + RAND_set_rand_method(&fuzz_rand_method); +} + + + int main(int argc, char **argv) { int n; |