comparison fuzz/fuzz-common.c @ 1758:1365661f6be6

Disable stderr output for fuzzer by default
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Oct 2020 22:40:08 +0800
parents 517fb7b62438
children 2406a9987810
comparison
equal deleted inserted replaced
1757:517fb7b62438 1758:1365661f6be6
9 #include "dbrandom.h" 9 #include "dbrandom.h"
10 #include "bignum.h" 10 #include "bignum.h"
11 #include "atomicio.h" 11 #include "atomicio.h"
12 #include "fuzz-wrapfd.h" 12 #include "fuzz-wrapfd.h"
13 13
14 /* fuzz.h redefines stderr, we don't want that here */
15 #undef stderr
16
14 struct dropbear_fuzz_options fuzz; 17 struct dropbear_fuzz_options fuzz;
15 18
16 static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param); 19 static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param);
17 static void load_fixed_hostkeys(void); 20 static void load_fixed_hostkeys(void);
18 static void load_fixed_client_key(void); 21 static void load_fixed_client_key(void);
22
23 // This runs automatically before main, due to contructor attribute in fuzz.h
24 void fuzz_early_setup(void) {
25 /* Set stderr to point to normal stderr by default */
26 fuzz.stderr = stderr;
27 }
19 28
20 void fuzz_common_setup(void) { 29 void fuzz_common_setup(void) {
21 disallow_core(); 30 disallow_core();
22 fuzz.fuzzing = 1; 31 fuzz.fuzzing = 1;
23 fuzz.wrapfds = 1; 32 fuzz.wrapfds = 1;
26 _dropbear_log = fuzz_dropbear_log; 35 _dropbear_log = fuzz_dropbear_log;
27 crypto_init(); 36 crypto_init();
28 fuzz_seed("start", 5); 37 fuzz_seed("start", 5);
29 /* let any messages get flushed */ 38 /* let any messages get flushed */
30 setlinebuf(stdout); 39 setlinebuf(stdout);
40 #if DEBUG_TRACE
41 if (debug_trace)
42 {
43 fprintf(stderr, "Dropbear fuzzer: -v specified, not disabling stderr output\n");
44 }
45 else
46 #endif
47 {
48 fprintf(stderr, "Dropbear fuzzer: Disabling stderr output\n");
49 fuzz.stderr = fopen("/dev/null", "w");
50 assert(fuzz.stderr);
51 }
31 } 52 }
32 53
33 int fuzz_set_input(const uint8_t *Data, size_t Size) { 54 int fuzz_set_input(const uint8_t *Data, size_t Size) {
34 55
35 fuzz.input->data = (unsigned char*)Data; 56 fuzz.input->data = (unsigned char*)Data;