From 5b6fd2a3140fa70a86a65631a20bf39d75e89c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=9Alusarz?= Date: Wed, 9 Sep 2020 18:48:16 +0200 Subject: [PATCH] intel/tools: handle ftell errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by Coverity, as "argument cannot be negative", referring to fread's 2nd argument. Signed-off-by: Marcin Ĺšlusarz Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/tools/i965_disasm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/intel/tools/i965_disasm.c b/src/intel/tools/i965_disasm.c index 401ca860cb4..3c8eaff33ea 100644 --- a/src/intel/tools/i965_disasm.c +++ b/src/intel/tools/i965_disasm.c @@ -38,10 +38,10 @@ enum opt_input_type { static enum opt_input_type input_type = OPT_INPUT_BINARY; /* Return size of file in bytes pointed by fp */ -static size_t +static long i965_disasm_get_file_size(FILE *fp) { - size_t size; + long size; fseek(fp, 0L, SEEK_END); size = ftell(fp); @@ -93,7 +93,11 @@ i965_disasm_read_binary(FILE *fp, size_t *end) size_t size; void *assembly; - *end = i965_disasm_get_file_size(fp); + long sz = i965_disasm_get_file_size(fp); + if (sz < 0) + return NULL; + + *end = (size_t)sz; if (!*end) return NULL;