X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fctf%2Fcommon%2Fmetadata%2Fdecoder.c;h=559820b350e953e9e077d6539a842f4910674f4b;hb=47eba00af0f5633717f8139041e2ec257ec39da1;hp=b6d3e48473ddf707bc30bbbf89b5a917b6539039;hpb=61d6f9b14a895f1a816a938844c371040f7cbd28;p=babeltrace.git diff --git a/plugins/ctf/common/metadata/decoder.c b/plugins/ctf/common/metadata/decoder.c index b6d3e484..559820b3 100644 --- a/plugins/ctf/common/metadata/decoder.c +++ b/plugins/ctf/common/metadata/decoder.c @@ -291,6 +291,13 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf_with_mdec( /* Close stream, which also flushes the buffer */ ret = bt_close_memstream(buf, &size, out_fp); + /* + * See fclose(3). Further access to out_fp after both success + * and error, even through another bt_close_memstream(), results + * in undefined behavior. Nullify out_fp to ensure we don't + * fclose it twice on error. + */ + out_fp = NULL; if (ret < 0) { BT_LOGE("Cannot close memory stream: %s: mdec-addr=%p", strerror(errno), mdec); @@ -431,6 +438,12 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_decode( BT_LOGD("Metadata stream is plain text: mdec-addr=%p", mdec); + if (init_pos < 0) { + BT_LOGE_ERRNO("Failed to get current file position", "."); + status = CTF_METADATA_DECODER_STATUS_ERROR; + goto end; + } + /* Check text-only metadata header and version */ nr_items = fscanf(fp, "/* CTF %10u.%10u", &major, &minor); if (nr_items < 2) {