From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============6815557080845701134==" MIME-Version: 1.0 From: Mark Wielaard To: elfutils-devel@lists.fedorahosted.org Subject: [PATCH] Fix GCC6 -Wnull-dereference warnings. Date: Sat, 13 Feb 2016 00:08:43 +0100 Message-ID: <1455318523-18008-1-git-send-email-mjw@redhat.com> --===============6815557080845701134== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable asm_begin.c: In function =E2=80=98asm_begin=E2=80=99: asm_begin.c:62:7: error: potential null pointer dereference [-Werror=3Dnull= -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 =E2=80=98handle_elf.constprop=E2=80=99: strip.c:1270:31: error: null pointer dereference [-Werror=3Dnull-dereferenc= e] elf_assert ((versiondata->d_size / sizeof (Elf32_Word)) ~~~~~~~~~~~^~~ src/strip.c:597:37: note: in definition of macro =E2=80=98elf_assert=E2=80= =99 #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 --- libasm/ChangeLog | 5 +++++ libasm/asm_begin.c | 4 ++-- src/ChangeLog | 4 ++++ src/strip.c | 6 ++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index beb6211..a8ac2c7 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,8 @@ +2016-02-12 Mark Wielaard + + * asm_begin.c (prepare_text_output): Only call __fsetlocking when + result isn't NULL. + 2015-10-05 Josh Stone = * Makefile.am (libasm.so): Add AM_V_CCLD and AM_V_at silencers. diff --git a/libasm/asm_begin.c b/libasm/asm_begin.c index ff4d94c..dc83cd8 100644 --- a/libasm/asm_begin.c +++ b/libasm/asm_begin.c @@ -58,8 +58,8 @@ prepare_text_output (AsmCtx_t *result) free (result); result =3D NULL; } - - __fsetlocking (result->out.file, FSETLOCKING_BYCALLER); + else + __fsetlocking (result->out.file, FSETLOCKING_BYCALLER); } = return result; diff --git a/src/ChangeLog b/src/ChangeLog index 71709e4..369b12c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2016-02-12 Mark Wielaard + + * strip.c (handle_elf): Correct elf_assert shndxdata check. + 2016-02-09 Mark Wielaard = * readelf.c (read_encoded): Move up. diff --git a/src/strip.c b/src/strip.c index 06d7cfd..a604244 100644 --- a/src/strip.c +++ b/src/strip.c @@ -1267,8 +1267,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, co= nst char *fname, shndxdata =3D elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, NULL); = - elf_assert ((versiondata->d_size / sizeof (Elf32_Word)) - >=3D shdr_info[cnt].data->d_size / elsize); + elf_assert (shndxdata !=3D NULL + && shndxdata->d_buf !=3D NULL + && ((shndxdata->d_size / sizeof (Elf32_Word)) + >=3D shdr_info[cnt].data->d_size / elsize)); } = if (shdr_info[cnt].version_idx !=3D 0) -- = 2.5.0 --===============6815557080845701134==--