Skip to content

Commit c41ea69

Browse files
committed
fix coap_parse_parms: use-after-free on uninitialized buf_t pointer
coap_parse_parms declared buf_t *b without initializing to NULL. When parse_var_bytes returned 0 (e.g. empty input), it did not write to its output parameter, leaving b as a garbage pointer. The subsequent bfree(b) freed an arbitrary address. Initialize b to 0 so bfree is a safe no-op on the error path. Found by libFuzzer with AddressSanitizer: ef hex coap-parms par
1 parent 51f1429 commit c41ea69

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/ef-coap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ buf_t *coap_parse_token(hdr_t *hdr, int hdr_offset, const char *s, int bytes) {
8080

8181
int coap_parse_parms(hdr_t *hdr, int hdr_offset, struct field *f, int argc, const char *argv[]){
8282
int res;
83-
buf_t *b, *bb = 0;
83+
buf_t *b = 0, *bb = 0;
8484

8585
res = parse_var_bytes(&b, argc, argv);
8686

0 commit comments

Comments
 (0)