annotate fuzzer-verify.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents a90fdd2d2ed8
children 66a1a2547133
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include "fuzz.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #include "session.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 #include "fuzz-wrapfd.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #include "debug.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 static void setup_fuzzer(void) {
1456
a90fdd2d2ed8 add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents: 1380
diff changeset
7 fuzz_common_setup();
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 static buffer *verifydata;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 /* Tests reading a public key and verifying a signature */
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 static int once = 0;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 if (!once) {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 setup_fuzzer();
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 verifydata = buf_new(30);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 buf_putstring(verifydata, "x", 1);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 once = 1;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21
1456
a90fdd2d2ed8 add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents: 1380
diff changeset
22 if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 return 0;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 m_malloc_set_epoch(1);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 if (setjmp(fuzz.jmp) == 0) {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 sign_key *key = new_sign_key();
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 enum signkey_type type = DROPBEAR_SIGNKEY_ANY;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 if (buf_get_pub_key(fuzz.input, key, &type) == DROPBEAR_SUCCESS) {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 /* Don't expect random fuzz input to verify */
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 assert(buf_verify(fuzz.input, key, verifydata) == DROPBEAR_FAILURE);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 sign_key_free(key);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 m_malloc_free_epoch(1, 0);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 } else {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 m_malloc_free_epoch(1, 1);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 TRACE(("dropbear_exit longjmped"))
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 // dropbear_exit jumped here
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 return 0;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 }