Skip to content

Commit d2b61c2

Browse files
arthurscchanmrdeep1
authored andcommitted
OSS-Fuzz: Add oscore conf parse fuzzer
1 parent 0bcd592 commit d2b61c2

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "coap3/coap_internal.h"
2+
3+
int
4+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
5+
coap_oscore_conf_t *oscore_conf;
6+
coap_str_const_t conf_mem;
7+
cose_encrypt0_t cose[1];
8+
uint8_t *buf;
9+
10+
if (size < 1)
11+
return 0;
12+
13+
/* Initialize libcoap */
14+
coap_startup();
15+
coap_set_log_level(COAP_LOG_EMERG);
16+
17+
/* The coap_new_oscore_conf() API expects null-terminated input data. */
18+
buf = (uint8_t *)malloc(size + 1);
19+
if (buf == NULL) {
20+
coap_cleanup();
21+
return 0;
22+
}
23+
memcpy(buf, data, size);
24+
buf[size] = '\0';
25+
26+
/* Initialisation */
27+
conf_mem.s = buf;
28+
conf_mem.length = size + 1;
29+
30+
/* Attempt to parse the fuzzer input as OSCORE configuration */
31+
oscore_conf = coap_new_oscore_conf(conf_mem, NULL, NULL, 0);
32+
33+
/* Clean up if parsing succeeded */
34+
if (oscore_conf) {
35+
coap_delete_oscore_conf(oscore_conf);
36+
}
37+
38+
free(buf);
39+
40+
/* Attempt to decode OSCORE option value */
41+
cose_encrypt0_init(cose);
42+
oscore_decode_option_value(data, size, cose);
43+
44+
coap_cleanup();
45+
return 0;
46+
}

0 commit comments

Comments
 (0)