Fix babeltrace-log (output) handling in ctf.c
[babeltrace.git] / formats / ctf / ctf.c
index 2048d6a0f2de776a8e440233e8e514ed039c472a..a20e6a7599053495f484a51480f9312093764451 100644 (file)
@@ -427,12 +427,12 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
        }
 
        /* update trace_packet_header and stream_packet_context */
-       if (file_stream->stream.trace_packet_header) {
+       if (pos->prot != PROT_WRITE && file_stream->stream.trace_packet_header) {
                /* Read packet header */
                ret = generic_rw(&pos->parent, &file_stream->stream.trace_packet_header->p);
                assert(!ret);
        }
-       if (file_stream->stream.stream_packet_context) {
+       if (pos->prot != PROT_WRITE && file_stream->stream.stream_packet_context) {
                /* Read packet context */
                ret = generic_rw(&pos->parent, &file_stream->stream.stream_packet_context->p);
                assert(!ret);
@@ -508,7 +508,7 @@ int ctf_open_trace_metadata_packet_read(struct ctf_trace *td, FILE *in,
                        return -EINVAL;
        }
 
-       toread = header.content_size / CHAR_BIT;
+       toread = (header.content_size / CHAR_BIT) - header_sizeof(header);
 
        for (;;) {
                readlen = fread(buf, sizeof(char), min(sizeof(buf), toread), in);
@@ -784,6 +784,9 @@ int create_stream_packet_index(struct ctf_trace *td,
        if (ret < 0)
                return ret;
 
+       if (filestats.st_size < MAX_PACKET_HEADER_LEN / CHAR_BIT)
+               return -EINVAL;
+
        for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
                uint64_t stream_id = 0;
 
This page took 0.023844 seconds and 4 git commands to generate.