From: Mathieu Desnoyers Date: Wed, 26 Jul 2017 15:55:11 +0000 (-0400) Subject: Fix: missing ftell/fseek error handling X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=677e1a210d1e5ca6ab5dbc17869754801c99edd6 Fix: missing ftell/fseek error handling 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 --- 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) {