This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH, BUILDROBOT] readelf.c:process_dynamic_section(): signed-vs-unsigned warning in format string (was: gdb and binutils branch master updated. 071436c6e94be13904438b6eb70ee79c73354a61)
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Jan-Benedict Glaw <jbglaw at lug-owl dot de>
- Cc: Nick Clifton <nickc at redhat dot com>, Binutils <binutils at sourceware dot org>
- Date: Fri, 7 Nov 2014 13:44:21 -0800
- Subject: Re: [PATCH, BUILDROBOT] readelf.c:process_dynamic_section(): signed-vs-unsigned warning in format string (was: gdb and binutils branch master updated. 071436c6e94be13904438b6eb70ee79c73354a61)
- Authentication-results: sourceware.org; auth=none
- References: <20141107134042 dot 2829 dot qmail at sourceware dot org> <20141107180550 dot GC27340 at lug-owl dot de>
On Fri, Nov 7, 2014 at 10:05 AM, Jan-Benedict Glaw <jbglaw@lug-owl.de> wrote:
> On Fri, 2014-11-07 13:40:42 -0000, nickc@sourceware.org <nickc@sourceware.org> wrote:
>> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=071436c6e94be13904438b6eb70ee79c73354a61
>>
>> commit 071436c6e94be13904438b6eb70ee79c73354a61
>> Author: Nick Clifton <nickc@redhat.com>
>> Date: Fri Nov 7 13:39:45 2014 +0000
>>
>> Add more fixes for inavlid memory accesses triggered by corrupt files.
>>
>> PR binutils/17531
>> * readelf.c (get_data): Avoid allocating memory when we know that
>> the read will fail.
>> (find_section_by_type): New function.
>> (get_unwind_section_word): Check for invalid symbol indicies.
>> Check for invalid reloc types.
>> (get_32bit_dynamic_section): Add range checks.
>> (get_64bit_dynamic_section): Add range checks.
>> (process_dynamic_section): Check for a corrupt time value.
>
>
> My build robot found this on gcc111:
>
> /bin/sh ./libtool --tag=CC --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -static-libstdc++ -static-libgcc -Wl,-bbigtoc -o addr2line addr2line.o bucomm.o version.o filemode.o ../bfd/libbfd.la ../libiberty/libiberty.a -lintl -lz
> libtool: link: gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -static-libstdc++ -static-libgcc -Wl,-bbigtoc -o addr2line addr2line.o bucomm.o version.o filemode.o ../bfd/.libs/libbfd.a ../libiberty/libiberty.a -L/opt/freeware/lib -lintl -L/users3/olivap/sb/p64/export/power_510_32/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/sh_dev_GNOME/export/power_510_32/usr/lib -L/gestconf/project/GNOME_ACL/GNOME/build/latest/export/power_510_32/usr/lib -L/users/project/PDP/PDP_51_050/usr/ccs/lib -L/users/project/PDP/PDP_51_050/usr/lib -liconv -lz -Wl,-blibpath:/opt/freeware/lib:/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/4.8.1:/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/4.8.1/../../..:/usr/lib:/lib
> gcc -DHAVE_CONFIG_H -I. -I/home/jbglaw/repos/binutils_gdb/binutils -I. -I/home/jbglaw/repos/binutils_gdb/binutils -I../bfd -I/home/jbglaw/repos/binutils_gdb/binutils/../bfd -I/home/jbglaw/repos/binutils_gdb/binutils/../include -DLOCALEDIR="\"/home/jbglaw/build/xstormy16-elf/_install_/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -MT readelf.o -MD -MP -MF .deps/readelf.Tpo -c -o readelf.o /home/jbglaw/repos/binutils_gdb/binutils/readelf.c
> /home/jbglaw/repos/binutils_gdb/binutils/readelf.c: In function 'process_dynamic_section':
> /home/jbglaw/repos/binutils_gdb/binutils/readelf.c:8883:3: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'time_t' [-Werror=format=]
> printf (_("<corrupt time val: %lx"), atime);
> ^
> cc1: all warnings being treated as errors
> make[3]: *** [readelf.o] Error 1
>
> I propose this:
>
> 2014-11-07 Jan-Benedict Glaw <jbglaw@lug-owl.de>
>
> * readelf.c (process_dynamic_section): Fix warning.
>
> diff --git a/binutils/ChangeLog b/binutils/ChangeLog
> index b0c6bb2..5d54de6 100644
> --- a/binutils/ChangeLog
> +++ b/binutils/ChangeLog
> @@ -1,3 +1,7 @@
> +2014-11-07 Jan-Benedict Glaw <jbglaw@lug-owl.de>
> +
> + * readelf.c (process_dynamic_section): Fix warning.
> +
> 2014-11-07 Nick Clifton <nickc@redhat.com>
>
> PR binutils/17531
> diff --git a/binutils/readelf.c b/binutils/readelf.c
> index 5bd3a4b..83318c1 100644
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -8880,7 +8880,7 @@ process_dynamic_section (FILE * file)
> tmp = gmtime (&atime);
> /* PR 17533 file: 041-1244816-0.004. */
> if (tmp == NULL)
> - printf (_("<corrupt time val: %lx"), atime);
> + printf (_("<corrupt time val: %lx"), (unsigned long) atime);
> else
> printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
> tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
>
>
> --
> Jan-Benedict Glaw jbglaw@lug-owl.de +49-172-7608481
> Signature of: God put me on earth to accomplish a certain number of
> the second : things. Right now I am so far behind I will never die.
I checked in a similar patch.
--
H.J.
---
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index b0c6bb2..b1ef9fa 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2014-11-07 H.J. Lu <hongjiu.lu@intel.com>
+
+ * readelf.c (process_dynamic_section): Cast time value to unsigned
+ long to print.
+
2014-11-07 Nick Clifton <nickc@redhat.com>
PR binutils/17531
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 5bd3a4b..e13bef1 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -8880,7 +8880,8 @@ process_dynamic_section (FILE * file)
tmp = gmtime (&atime);
/* PR 17533 file: 041-1244816-0.004. */
if (tmp == NULL)
- printf (_("<corrupt time val: %lx"), atime);
+ printf (_("<corrupt time val: %lx"),
+ (unsigned long) atime);
else
printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,