Install custom RAND_METHOD for fuzzing
[openssl.git] / fuzz / test-corpus.c
index ccad369fafe837bf11086fd7634e809222e0b458..a876f209c9cf63d407c075bf907aae4aa84c5f47 100644 (file)
 #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;
 
@@ -33,6 +64,8 @@ int main(int argc, char **argv) {
 
         stat(argv[n], &st);
         f = fopen(argv[n], "rb");
+        if (f == NULL)
+            continue;
         buf = malloc(st.st_size);
         s = fread(buf, 1, st.st_size, f);
         OPENSSL_assert(s == (size_t)st.st_size);
@@ -40,5 +73,8 @@ int main(int argc, char **argv) {
         free(buf);
         fclose(f);
     }
+
+    FuzzerCleanup();
+
     return 0;
 }