]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elflint.c: Don't dereference databits if bad
authorMark Wielaard <mark@klomp.org>
Wed, 6 Oct 2021 21:37:42 +0000 (23:37 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 6 Oct 2021 21:41:00 +0000 (23:41 +0200)
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 <jbglaw@lug-owl.de>
Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/elflint.c

index 87b3dd461b09ca89cd781adc3f7bbd7c844aec5d..316bcb6d5d205cf4a1c28402c225d447aa29da98 100644 (file)
@@ -1,3 +1,7 @@
+2021-10-06  Mark Wielaard  <mark@klomp.org>
+
+       * elflint.c (check_sections): Don't dereference databits if bad.
+
 2021-09-09  Dmitry V. Levin  <ldv@altlinux.org>
 
        * findtextrel.c: Include "libeu.h".
index 1ce7568473295cb9e7e99daf34e252db8ce7c934..ef7725ce7f30c3a365062edfb8ef2d04b959e2c5 100644 (file)
@@ -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;