Skip to content

Commit

Permalink
CIFuzz: Make sure libcoap is running when calling coap_delete_pdu()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Jan 28, 2025
1 parent ba09d0f commit d585d34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tests/oss-fuzz/pdu_parse_tcp_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ size_t coap_pdu_encode_header(coap_pdu_t *, coap_proto_t);

int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, size);
coap_pdu_t *pdu;

coap_startup();
pdu = coap_pdu_init(0, 0, 0, size);
if (pdu) {
coap_set_log_level(COAP_LOG_ERR);
if (coap_pdu_parse(COAP_PROTO_TCP, data, size, pdu)) {
Expand All @@ -19,5 +22,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
coap_delete_pdu(pdu);
}
coap_cleanup();
return 0;
}
8 changes: 7 additions & 1 deletion tests/oss-fuzz/pdu_parse_udp_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ size_t coap_pdu_encode_header(coap_pdu_t *, coap_proto_t);

int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, size);
coap_pdu_t *pdu;

coap_startup();
pdu = coap_pdu_init(0, 0, 0, size);
if (pdu) {
coap_set_log_level(COAP_LOG_ERR);
if (coap_pdu_parse(COAP_PROTO_UDP, data, size, pdu)) {
Expand All @@ -17,7 +20,10 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
coap_delete_string(query);
coap_delete_string(uri_path);
}
else
coap_log_err("PDU failed\n");
coap_delete_pdu(pdu);
}
coap_cleanup();
return 0;
}
6 changes: 5 additions & 1 deletion tests/oss-fuzz/pdu_parse_ws_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ size_t coap_pdu_encode_header(coap_pdu_t *, coap_proto_t);

int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, size);
coap_pdu_t *pdu;

coap_startup();
pdu = coap_pdu_init(0, 0, 0, size);
if (pdu) {
coap_set_log_level(COAP_LOG_ERR);
if (coap_pdu_parse(COAP_PROTO_WS, data, size, pdu)) {
Expand All @@ -19,5 +22,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
coap_delete_pdu(pdu);
}
coap_cleanup();
return 0;
}

0 comments on commit d585d34

Please sign in to comment.