From: Mathieu Desnoyers Date: Sat, 7 May 2011 06:01:22 +0000 (-0400) Subject: Add checks on packet and content size X-Git-Tag: v0.1~87 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=546293fa85416f739f1cfc125c5c4bcd25075a5d Add checks on packet and content size Signed-off-by: Mathieu Desnoyers --- diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 08834e97..717f48d4 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -448,6 +448,21 @@ int create_stream_packet_index(struct ctf_trace *td, /* Use content size if non-zero, else file size */ packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT; } + + /* Validate content size and packet size values */ + if (packet_index.content_size > packet_index.packet_size) { + fprintf(stdout, "[error] Content size (%zu bits) is larger than packet size (%zu bits).\n", + packet_index.content_size, packet_index.packet_size); + return -EINVAL; + } + + if (packet_index.packet_size > filestats.st_size * CHAR_BIT) { + fprintf(stdout, "[error] Packet size (%zu bits) is larger than file size (%zu bits).\n", + packet_index.content_size, filestats.st_size * CHAR_BIT); + return -EINVAL; + } + + /* Save position after header and context */ packet_index.data_offset = pos->offset;