Fix: Unchecked array index when importing trace indexes
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 13 Feb 2014 19:42:36 +0000 (14:42 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 13 Feb 2014 19:42:36 +0000 (14:42 -0500)
import_stream_packet_index may access the streams array with an invalid
stream_id index when a stream has an index but is not declared in the
trace's metadata.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ctf.c

index 141f9bfae0c7c7dd040471d74c725fc97a622bc0..6d21b876dad422628f0884ea7e9e21be7c2db063 100644 (file)
@@ -1811,7 +1811,6 @@ static
 int import_stream_packet_index(struct ctf_trace *td,
                struct ctf_file_stream *file_stream)
 {
 int import_stream_packet_index(struct ctf_trace *td,
                struct ctf_file_stream *file_stream)
 {
-       struct ctf_stream_declaration *stream;
        struct ctf_stream_pos *pos;
        struct ctf_packet_index ctf_index;
        struct ctf_packet_index_file_hdr index_hdr;
        struct ctf_stream_pos *pos;
        struct ctf_packet_index ctf_index;
        struct ctf_packet_index_file_hdr index_hdr;
@@ -1852,6 +1851,7 @@ int import_stream_packet_index(struct ctf_trace *td,
        while (fread(&ctf_index, index_hdr.packet_index_len, 1,
                        pos->index_fp) == 1) {
                uint64_t stream_id;
        while (fread(&ctf_index, index_hdr.packet_index_len, 1,
                        pos->index_fp) == 1) {
                uint64_t stream_id;
+               struct ctf_stream_declaration *stream = NULL;
 
                memset(&index, 0, sizeof(index));
                index.offset = be64toh(ctf_index.offset);
 
                memset(&index, 0, sizeof(index));
                index.offset = be64toh(ctf_index.offset);
@@ -1871,7 +1871,9 @@ int import_stream_packet_index(struct ctf_trace *td,
                }
 
                file_stream->parent.stream_id = stream_id;
                }
 
                file_stream->parent.stream_id = stream_id;
-               stream = g_ptr_array_index(td->streams, stream_id);
+               if (stream_id < td->streams->len) {
+                       stream = g_ptr_array_index(td->streams, stream_id);
+               }
                if (!stream) {
                        fprintf(stderr, "[error] Stream %" PRIu64
                                        " is not declared in metadata.\n",
                if (!stream) {
                        fprintf(stderr, "[error] Stream %" PRIu64
                                        " is not declared in metadata.\n",
This page took 0.025805 seconds and 4 git commands to generate.