From 677e1a210d1e5ca6ab5dbc17869754801c99edd6 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 26 Jul 2017 11:55:11 -0400 Subject: [PATCH] Fix: missing ftell/fseek error handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Found by Coverity: CID 1376181 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS). negative_returns: filesize is passed to a parameter that cannot be negative. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- plugins/ctf/fs-src/query.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index 3c53b51c..670a8f13 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -100,8 +100,16 @@ struct bt_value *metadata_info_query(struct bt_component_class *comp_class, } else { long filesize; - fseek(metadata_fp, 0, SEEK_END); + ret = fseek(metadata_fp, 0, SEEK_END); + if (ret) { + fprintf(stderr, "Error in fseek: %s", strerror(errno)); + goto error; + } filesize = ftell(metadata_fp); + if (filesize < 0) { + fprintf(stderr, "Error in ftell: %s", strerror(errno)); + goto error; + } rewind(metadata_fp); metadata_text = malloc(filesize + 1); if (!metadata_text) { -- 2.34.1