From 0e1b84aa80398d5573b73ae4d6ae79d6a930a2fd Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 9 Feb 2016 13:27:22 -0500 Subject: [PATCH 1/1] Fix: out-of-bound memory access MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We need to check for end of stream before updating the current packet index, else we access memory beyond the last stream packet index array element. This fixes valgrind errors which appear at commit 480ef05 Support ctf index version 1.1 due to change of the element size, but actually caused by commit 2654fe9 Fix: events discarded timing inaccuracy Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- formats/ctf/ctf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 9cb19f4d..fb9b2333 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -936,6 +936,11 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence) assert(0); } + if (pos->cur_index >= pos->packet_index->len) { + pos->offset = EOF; + return; + } + packet_index = &g_array_index(pos->packet_index, struct packet_index, pos->cur_index); if (pos->cur_index > 0) { @@ -948,11 +953,6 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence) ctf_update_current_packet_index(&file_stream->parent, prev_index, packet_index); - if (pos->cur_index >= pos->packet_index->len) { - pos->offset = EOF; - return; - } - /* * We need to check if we are in trace read or called * from packet indexing. In this last case, the -- 2.34.1