X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fctf.c;h=5f263cd36e9a50bae29981ba1d9daba24920c62d;hb=8793d9f8b7d71898bd3097af5e584517268370d4;hp=759708856b0a2044c4802325d2a2434ae0525287;hpb=2d686891bc3f1a80bff4bfdcea70f30a057ee388;p=babeltrace.git diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 75970885..5f263cd3 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -471,6 +471,11 @@ int ctf_read_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *str */ if (unlikely(pos->offset == EOF)) return EOF; + + if (pos->content_size == 0) { + /* Stream is inactive for now (live reading). */ + return EAGAIN; + } assert(pos->offset < pos->content_size); /* Read event header */ @@ -1572,6 +1577,11 @@ begin: return -EINVAL; } + if (packet_index.content_size < pos->offset) { + fprintf(stderr, "[error] Invalid CTF stream: content size is smaller than packet headers.\n"); + 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; @@ -1716,6 +1726,11 @@ int import_stream_packet_index(struct ctf_trace *td, ret = -1; goto error; } + if (index_hdr.packet_index_len == 0) { + fprintf(stderr, "[error] Packet index length cannot be 0.\n"); + ret = -1; + goto error; + } while ((index_read = fread(&ctf_index, index_hdr.packet_index_len, 1, pos->index_fp)) == 1) { @@ -1849,6 +1864,10 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags, goto error_free; } file_stream->pos.index_fp = fdopen(ret, "r"); + if (!file_stream->pos.index_fp) { + perror("fdopen() error"); + goto error_free; + } ret = import_stream_packet_index(td, file_stream); if (ret) { ret = -1;