From: Mark Wielaard Date: Wed, 6 Oct 2021 21:37:42 +0000 (+0200) Subject: elflint.c: Don't dereference databits if bad X-Git-Tag: elfutils-0.186~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3d9f12883d0c131bd4ab6045e1f60d3fe6d150ea;p=thirdparty%2Felfutils.git elflint.c: Don't dereference databits if bad elflint.c: In function 'check_sections': elflint.c:4105:48: error: null pointer dereference [-Werror=null-dereference] 4105 | idx < databits->d_size && ! bad; | ~~~~~~~~^~~~~~~~ Fix this by testing for ! bad first. Reported-by: Jan-Benedict Glaw Signed-off-by: Mark Wielaard --- diff --git a/src/ChangeLog b/src/ChangeLog index 87b3dd461..316bcb6d5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2021-10-06 Mark Wielaard + + * elflint.c (check_sections): Don't dereference databits if bad. + 2021-09-09 Dmitry V. Levin * findtextrel.c: Include "libeu.h". diff --git a/src/elflint.c b/src/elflint.c index 1ce756847..ef7725ce7 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -4102,7 +4102,7 @@ section [%2zu] '%s' has type NOBITS but is read from the file in segment of prog bad = (databits == NULL || databits->d_size != shdr->sh_size); for (size_t idx = 0; - idx < databits->d_size && ! bad; + ! bad && idx < databits->d_size; idx++) bad = ((char *) databits->d_buf)[idx] != 0;