Add checks on packet and content size
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 06:01:22 +0000 (02:01 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 06:01:22 +0000 (02:01 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c

index 08834e9744318e944ae97ad006c43f8ca79b8bb0..717f48d4cf1bbdd81bc8e676c1e325e02fa9c83b 100644 (file)
@@ -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;
 
This page took 0.025005 seconds and 4 git commands to generate.