* Section Header Block.
*/
#define BT_SHB 0x0A0D0D0A
-
+#define BT_SHB_INSANE_MAX 1024*1024*1 /* 1MB should be enough */
struct section_header_block {
bpf_u_int32 byte_order_magic;
u_short major_version;
if (amt_read == 0 && !fail_on_eof)
return (0); /* EOF */
snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "truncated dump file; tried to read %zu bytes, only got %zu",
+ "truncated pcapng dump file; tried to read %zu bytes, only got %zu",
bytes_to_read, amt_read);
}
return (-1);
/*
* Check the sanity of the total length.
*/
- if (total_length < sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer)) {
+ if (total_length < sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer) ||
+ (total_length > BT_SHB_INSANE_MAX)) {
snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "Section Header Block in pcapng dump file has a length of %u < %zu",
- total_length,
- sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer));
- *err = 1;
- return (NULL);
- }
+ "Section Header Block in pcapng dump file has invalid length %zu < _%lu_ < %lu (BT_SHB_INSANE_MAX)",
+ sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer),
+ total_length,
+ BT_SHB_INSANE_MAX);
- /*
- * Make sure it's not too big.
- */
- if (total_length > INITIAL_MAX_BLOCKSIZE) {
- snprintf(errbuf, PCAP_ERRBUF_SIZE,
- "pcapng block size %u > maximum %u",
- total_length, INITIAL_MAX_BLOCKSIZE);
*err = 1;
return (NULL);
}
+
+
/*
* OK, this is a good pcapng file.
* Allocate a pcap_t for it.