]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix GCC6 -Wnull-dereference warnings.
authorMark Wielaard <mjw@redhat.com>
Fri, 12 Feb 2016 22:59:32 +0000 (23:59 +0100)
committerMark Wielaard <mjw@redhat.com>
Mon, 22 Feb 2016 11:09:25 +0000 (12:09 +0100)
asm_begin.c: In function ‘asm_begin’:
asm_begin.c:62:7: error: potential null pointer dereference [-Werror=null-dereference]
       __fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We set result to NULL just before this call in case of error.
Fixed by only calling __fsetlocking when result is not NULL.

strip.c: In function ‘handle_elf.constprop’:
strip.c:1270:31: error: null pointer dereference [-Werror=null-dereference]
       elf_assert ((versiondata->d_size / sizeof (Elf32_Word))
                    ~~~~~~~~~~~^~~

src/strip.c:597:37: note: in definition of macro ‘elf_assert’
 #define elf_assert(test) do { if (!(test)) goto illformed; } while (0)
                                     ^~~~

That is the wrong check, we want to check shndxdata, not versiondata here.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libasm/ChangeLog
libasm/asm_begin.c
src/ChangeLog
src/strip.c

index beb6211c58943ac93fd6d5da3c6c77fe35f6d01f..a8ac2c7c3288675209da4e8d3badc42c8c294406 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-12  Mark Wielaard  <mjw@redhat.com>
+
+       * asm_begin.c (prepare_text_output): Only call __fsetlocking when
+       result isn't NULL.
+
 2015-10-05  Josh Stone  <jistone@redhat.com>
 
        * Makefile.am (libasm.so): Add AM_V_CCLD and AM_V_at silencers.
index ff4d94c23c9381178025f7b740c182334722d0c4..dc83cd8b57659dc2e431d5948e45489f104a331d 100644 (file)
@@ -58,8 +58,8 @@ prepare_text_output (AsmCtx_t *result)
          free (result);
          result = NULL;
        }
-
-      __fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
+      else
+       __fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
     }
 
   return result;
index 1c935d95c685d2824924f7dc7f1deddf83ccafc7..29782404394db5b4ff27fe06b0e6c8a481eeb19e 100644 (file)
@@ -1,3 +1,7 @@
+2016-02-12  Mark Wielaard  <mjw@redhat.com>
+
+       * strip.c (handle_elf): Correct elf_assert shndxdata check.
+
 2016-02-09  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (read_encoded): Move up.
index 06d7cfd850e70c584f3d72424bf798c3bc4d5d82..a6042445999cc4770d97e99a573e6f9550d396fe 100644 (file)
@@ -1267,8 +1267,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
                    shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
                                             NULL);
 
-                   elf_assert ((versiondata->d_size / sizeof (Elf32_Word))
-                               >= shdr_info[cnt].data->d_size / elsize);
+                   elf_assert (shndxdata != NULL
+                               && shndxdata->d_buf != NULL
+                               && ((shndxdata->d_size / sizeof (Elf32_Word))
+                                   >= shdr_info[cnt].data->d_size / elsize));
                  }
 
                if (shdr_info[cnt].version_idx != 0)