summaryrefslogtreecommitdiffstats
path: root/fuzz
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/asn1.c12
-rw-r--r--fuzz/client.c12
-rw-r--r--fuzz/fuzzer.h1
-rw-r--r--fuzz/server.c12
-rw-r--r--fuzz/test-corpus.c31
-rw-r--r--fuzz/x509.c12
6 files changed, 36 insertions, 44 deletions
diff --git a/fuzz/asn1.c b/fuzz/asn1.c
index c45fd79328..90262defd3 100644
--- a/fuzz/asn1.c
+++ b/fuzz/asn1.c
@@ -31,11 +31,6 @@
#include <openssl/rand.h>
#include "fuzzer.h"
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
-extern int rand_predictable;
-#endif
-#define ENTROPY_NEEDED 32
-
static ASN1_ITEM_EXP *item_type[] = {
ASN1_ITEM_ref(ACCESS_DESCRIPTION),
#ifndef OPENSSL_NO_RFC3779
@@ -216,12 +211,7 @@ int FuzzerInitialize(int *argc, char ***argv)
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_get_state();
CRYPTO_free_ex_index(0, -1);
- RAND_add("", 1, ENTROPY_NEEDED);
- RAND_status();
-
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
- rand_predictable = 1;
-#endif
+ FuzzerSetRand();
return 1;
}
diff --git a/fuzz/client.c b/fuzz/client.c
index 104938f42d..3bc4ad94f1 100644
--- a/fuzz/client.c
+++ b/fuzz/client.c
@@ -18,11 +18,6 @@
#include <openssl/err.h>
#include "fuzzer.h"
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
-extern int rand_predictable;
-#endif
-#define ENTROPY_NEEDED 32
-
/* unused, to avoid warning. */
static int idx;
@@ -50,16 +45,11 @@ int FuzzerInitialize(int *argc, char ***argv)
ERR_get_state();
CRYPTO_free_ex_index(0, -1);
idx = SSL_get_ex_data_X509_STORE_CTX_idx();
- RAND_add("", 1, ENTROPY_NEEDED);
- RAND_status();
+ FuzzerSetRand();
comp_methods = SSL_COMP_get_compression_methods();
OPENSSL_sk_sort((OPENSSL_STACK *)comp_methods);
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
- rand_predictable = 1;
-#endif
-
return 1;
}
diff --git a/fuzz/fuzzer.h b/fuzz/fuzzer.h
index 5f9efa4bf6..fcc0d25279 100644
--- a/fuzz/fuzzer.h
+++ b/fuzz/fuzzer.h
@@ -11,3 +11,4 @@
int FuzzerTestOneInput(const uint8_t *buf, size_t len);
int FuzzerInitialize(int *argc, char ***argv);
void FuzzerCleanup(void);
+void FuzzerSetRand(void);
diff --git a/fuzz/server.c b/fuzz/server.c
index 397867f065..6cc1f7f3da 100644
--- a/fuzz/server.c
+++ b/fuzz/server.c
@@ -465,11 +465,6 @@ static const char DSACertPEM[] = {
};
#endif
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
-extern int rand_predictable;
-#endif
-#define ENTROPY_NEEDED 32
-
/* unused, to avoid warning. */
static int idx;
@@ -497,16 +492,11 @@ int FuzzerInitialize(int *argc, char ***argv)
ERR_get_state();
CRYPTO_free_ex_index(0, -1);
idx = SSL_get_ex_data_X509_STORE_CTX_idx();
- RAND_add("", 1, ENTROPY_NEEDED);
- RAND_status();
+ FuzzerSetRand();
comp_methods = SSL_COMP_get_compression_methods();
OPENSSL_sk_sort((OPENSSL_STACK *)comp_methods);
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
- rand_predictable = 1;
-#endif
-
return 1;
}
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;
diff --git a/fuzz/x509.c b/fuzz/x509.c
index 83b00f653f..0de61cd969 100644
--- a/fuzz/x509.c
+++ b/fuzz/x509.c
@@ -14,22 +14,12 @@
#include <openssl/rand.h>
#include "fuzzer.h"
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
-extern int rand_predictable;
-#endif
-#define ENTROPY_NEEDED 32
-
int FuzzerInitialize(int *argc, char ***argv)
{
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
ERR_get_state();
CRYPTO_free_ex_index(0, -1);
- RAND_add("", 1, ENTROPY_NEEDED);
- RAND_status();
-
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
- rand_predictable = 1;
-#endif
+ FuzzerSetRand();
return 1;
}