projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: use of file pointer after fclose()
[babeltrace.git]
/
plugins
/
ctf
/
common
/
metadata
/
decoder.c
diff --git
a/plugins/ctf/common/metadata/decoder.c
b/plugins/ctf/common/metadata/decoder.c
index b6d3e48473ddf707bc30bbbf89b5a917b6539039..559820b350e953e9e077d6539a842f4910674f4b 100644
(file)
--- 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);
/* 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);
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);
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) {
/* Check text-only metadata header and version */
nr_items = fscanf(fp, "/* CTF %10u.%10u", &major, &minor);
if (nr_items < 2) {
This page took
0.024055 seconds
and
4
git commands to generate.