From 2f866ff070bd81406f4e92a08273b5de64e2fe38 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Wed, 1 Aug 2018 10:02:20 +0000 Subject: [PATCH] better error handling, found by coverity. --- src/readelf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/readelf.c b/src/readelf.c index 5dfcea54..2c4cddb6 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: readelf.c,v 1.147 2018/08/01 09:56:24 christos Exp $") +FILE_RCSID("@(#)$File: readelf.c,v 1.148 2018/08/01 10:02:20 christos Exp $") #endif #ifdef BUILTIN_ELF @@ -921,7 +921,8 @@ get_string_on_virtaddr(struct magic_set *ms, offset = get_offset_from_virtaddr(ms, swap, clazz, fd, ph_off, ph_num, fsize, virtaddr); - if ((buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) { + if (offset < 0 || + (buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) { file_badread(ms); return 0; } -- 2.40.0