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 2a58189
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 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;
}
5 changes: 5 additions & 0 deletions tests/oss-fuzz/pdu_parse_udp_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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_startup();
pdu = coap_pdu_init(0, 0, 0, size);
coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, size);
if (pdu) {
coap_set_log_level(COAP_LOG_ERR);
Expand All @@ -19,5 +23,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
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 2a58189

Please sign in to comment.