From 2d686891bc3f1a80bff4bfdcea70f30a057ee388 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 27 Nov 2013 04:07:08 -0500 Subject: [PATCH] Fix: test for less than 1 byte packets Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 37f339c9..75970885 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -1554,9 +1554,9 @@ begin: } } else { /* Use file size for packet size */ - packet_index.content_size = filesize * CHAR_BIT; - /* Use content size if non-zero, else file size */ - packet_index.packet_size = packet_index.content_size ? : filesize * CHAR_BIT; + packet_index.packet_size = filesize * CHAR_BIT; + /* Use packet size if non-zero, else file size */ + packet_index.content_size = packet_index.packet_size ? : filesize * CHAR_BIT; } /* Validate content size and packet size values */ @@ -1572,6 +1572,11 @@ begin: return -EINVAL; } + if ((packet_index.packet_size >> LOG2_CHAR_BIT) == 0) { + fprintf(stderr, "[error] Invalid CTF stream: packet size needs to be at least one byte\n"); + return -EINVAL; + } + /* Save position after header and context */ packet_index.data_offset = pos->offset; -- 2.34.1