annotate fuzzer-pubkey.c @ 1369:ddfcadca3c4c fuzz

fuzzer-pubkey
author Matt Johnston <matt@ucc.asn.au>
date Tue, 23 May 2017 22:43:34 +0800
parents
children d4cc85e6c569
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1369
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include "fuzz.h"
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #include "session.h"
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 #include "fuzz-wrapfd.h"
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #include "debug.h"
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 static void setup_fuzzer(void) {
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 common_setup_fuzzer();
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 }
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 static int once = 0;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 if (!once) {
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 setup_fuzzer();
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 once = 1;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 }
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 m_malloc_set_epoch(1);
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 fuzz_seed();
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 fuzz.input->data = (unsigned char*)Data;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 fuzz.input->len = Size;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 fuzz.input->size = Size;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 fuzz.input->pos = 0;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 if (Size < 4) {
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 return 0;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 }
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 // choose a keytype based on input
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 uint8_t b = 0;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 size_t i;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 for (i = 0; i < Size; i++) {
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 b ^= Data[i];
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 }
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 const char* algoname = fuzz_signkey_names[b%DROPBEAR_SIGNKEY_NUM_NAMED];
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 const char* keyblob = "fakekeyblob";
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 if (setjmp(fuzz.jmp) == 0) {
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 fuzz_checkpubkey_line(fuzz.input, 5, "/home/me/authorized_keys",
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 algoname, strlen(algoname),
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 keyblob, strlen(keyblob));
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 } else {
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 m_malloc_free_epoch(1);
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 TRACE(("dropbear_exit longjmped"))
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 // dropbear_exit jumped here
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 }
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 return 0;
ddfcadca3c4c fuzzer-pubkey
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 }