comparison fuzzer-verify.c @ 1380:d201105df2ed fuzz

add fuzzer-verify
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 May 2017 00:20:01 +0800
parents
children a90fdd2d2ed8
comparison
equal deleted inserted replaced
1379:616417b27f55 1380:d201105df2ed
1 #include "fuzz.h"
2 #include "session.h"
3 #include "fuzz-wrapfd.h"
4 #include "debug.h"
5
6 static void setup_fuzzer(void) {
7 common_setup_fuzzer();
8 }
9
10 static buffer *verifydata;
11
12 /* Tests reading a public key and verifying a signature */
13 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
14 static int once = 0;
15 if (!once) {
16 setup_fuzzer();
17 verifydata = buf_new(30);
18 buf_putstring(verifydata, "x", 1);
19 once = 1;
20 }
21
22 if (fuzzer_set_input(Data, Size) == DROPBEAR_FAILURE) {
23 return 0;
24 }
25
26 m_malloc_set_epoch(1);
27
28 if (setjmp(fuzz.jmp) == 0) {
29 sign_key *key = new_sign_key();
30 enum signkey_type type = DROPBEAR_SIGNKEY_ANY;
31 if (buf_get_pub_key(fuzz.input, key, &type) == DROPBEAR_SUCCESS) {
32 /* Don't expect random fuzz input to verify */
33 assert(buf_verify(fuzz.input, key, verifydata) == DROPBEAR_FAILURE);
34 }
35 sign_key_free(key);
36 m_malloc_free_epoch(1, 0);
37 } else {
38 m_malloc_free_epoch(1, 1);
39 TRACE(("dropbear_exit longjmped"))
40 // dropbear_exit jumped here
41 }
42
43 return 0;
44 }