Skip to content

Commit 70a6aa2

Browse files
committed
Hardening: Fix memory leak in pcapng fail path and secure realloc logic
1 parent 8cdebf1 commit 70a6aa2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

sf-pcapng.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf)
343343
return (-1);
344344
}
345345
p->buffer = bigger_buffer;
346+
p->bufsize = bhdr.total_length;
346347
}
347348

348349
/*
@@ -902,9 +903,7 @@ pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision,
902903
default:
903904
snprintf(errbuf, PCAP_ERRBUF_SIZE,
904905
"unknown time stamp resolution %u", precision);
905-
free(p);
906-
*err = 1;
907-
return (NULL);
906+
goto fail;
908907
}
909908

910909
p->opt.tstamp_precision = precision;
@@ -931,9 +930,7 @@ pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision,
931930
p->buffer = malloc(p->bufsize);
932931
if (p->buffer == NULL) {
933932
snprintf(errbuf, PCAP_ERRBUF_SIZE, "out of memory");
934-
free(p);
935-
*err = 1;
936-
return (NULL);
933+
goto fail;
937934
}
938935
ps->max_blocksize = INITIAL_MAX_BLOCKSIZE;
939936

0 commit comments

Comments
 (0)