Mercurial > dropbear
annotate fuzzer-kexdh.c @ 1593:c8c20fb57a9a
Don't read uninitialised value.
From https://github.com/libtom/libtommath/commit/1d03522625f46214733e8e143a4765c01fc146f9
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 05 Mar 2018 16:50:24 +0800 |
parents | 46506b32650a |
children | 4fe7cc9e45eb |
rev | line source |
---|---|
1589 | 1 #include "fuzz.h" |
2 #include "session.h" | |
3 #include "fuzz-wrapfd.h" | |
4 #include "debug.h" | |
5 #include "runopts.h" | |
6 #include "algo.h" | |
7 #include "bignum.h" | |
8 | |
9 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | |
10 static int once = 0; | |
11 static struct key_context* keep_newkeys = NULL; | |
1592
46506b32650a
reduce number of params so it doesn't hit a timeout
Matt Johnston <matt@ucc.asn.au>
parents:
1589
diff
changeset
|
12 /* number of generated parameters is limited by the timeout for the first run */ |
46506b32650a
reduce number of params so it doesn't hit a timeout
Matt Johnston <matt@ucc.asn.au>
parents:
1589
diff
changeset
|
13 #define NUM_PARAMS 300 |
1589 | 14 static struct kex_dh_param *dh_params[NUM_PARAMS]; |
15 | |
16 if (!once) { | |
17 fuzz_common_setup(); | |
18 fuzz_svr_setup(); | |
19 | |
20 keep_newkeys = (struct key_context*)m_malloc(sizeof(struct key_context)); | |
21 keep_newkeys->algo_kex = fuzz_get_algo(sshkex, "diffie-hellman-group14-sha256"); | |
22 keep_newkeys->algo_hostkey = DROPBEAR_SIGNKEY_ECDSA_NISTP256; | |
23 ses.newkeys = keep_newkeys; | |
24 | |
25 /* Pre-generate parameters */ | |
26 int i; | |
27 for (i = 0; i < NUM_PARAMS; i++) { | |
28 dh_params[i] = gen_kexdh_param(); | |
29 } | |
30 | |
31 once = 1; | |
32 } | |
33 | |
34 if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) { | |
35 return 0; | |
36 } | |
37 | |
38 m_malloc_set_epoch(1); | |
39 | |
40 if (setjmp(fuzz.jmp) == 0) { | |
41 /* Based on recv_msg_kexdh_init()/send_msg_kexdh_reply() | |
42 with DROPBEAR_KEX_NORMAL_DH */ | |
43 ses.newkeys = keep_newkeys; | |
44 | |
45 /* Choose from the collection of ecdh params */ | |
46 unsigned int e = buf_getint(fuzz.input); | |
47 struct kex_dh_param * dh_param = dh_params[e % NUM_PARAMS]; | |
48 | |
49 DEF_MP_INT(dh_e); | |
50 m_mp_init(&dh_e); | |
51 if (buf_getmpint(fuzz.input, &dh_e) != DROPBEAR_SUCCESS) { | |
52 dropbear_exit("Bad kex value"); | |
53 } | |
54 | |
55 ses.kexhashbuf = buf_new(4); | |
56 buf_putint(ses.kexhashbuf, 12345); | |
57 kexdh_comb_key(dh_param, &dh_e, svr_opts.hostkey); | |
58 | |
59 /* kexhashbuf is freed in kexdh_comb_key */ | |
60 m_free(ses.dh_K); | |
61 mp_clear(&dh_e); | |
62 | |
63 m_malloc_free_epoch(1, 0); | |
64 } else { | |
65 m_malloc_free_epoch(1, 1); | |
66 TRACE(("dropbear_exit longjmped")) | |
67 /* dropbear_exit jumped here */ | |
68 } | |
69 | |
70 return 0; | |
71 } |