public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [Bug general/24068] New: readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32
@ 2019-01-06 15:58 marxin.liska at gmail dot com
  2019-01-13 17:02 ` [Bug general/24068] " mark at klomp dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: marxin.liska at gmail dot com @ 2019-01-06 15:58 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=24068

            Bug ID: 24068
           Summary: readelf.c:10152:15: error: ‘%*llx’ directive output
                    between 4 and 2147483647 bytes may cause result to
                    exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32
           Product: elfutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: general
          Assignee: unassigned at sourceware dot org
          Reporter: marxin.liska at gmail dot com
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

Using latest GCC and -m32 (on x86_64-linux-gnu), one can see:

$ gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/usr/local/share/locale"' 
-DDEBUGPRED=0 -DSRCDIR=\"/home/marxin/Programming/elfutils/src\"
-DOBJDIR=\"/home/marxin/Programming/elfutils/src\" -I. -I..  -I. -I. -I../lib
-I.. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../libdwfl
-I./../libasm  -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition
-Wstrict-prototypes -Wtrampolines -Wlogical-op -Wduplicated-cond
-Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra   
-D_FORTIFY_SOURCE=2 -g -O2 -MT readelf.o -MD -MP -MF .deps/readelf.Tpo -c -o
readelf.o readelf.c -m32
readelf.c: In function ‘print_debug_str_section’:
readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647
bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=]
10152 |       printf (" [%*" PRIx64 "]  \"%s\"\n", digits, (uint64_t) offset,
str);
      |               ^~~~~~
readelf.c:10152:18: note: format string is defined here
10152 |       printf (" [%*" PRIx64 "]  \"%s\"\n", digits, (uint64_t) offset,
str);
readelf.c:10152:15: note: directive argument in the range [0,
18446744073709551614]
10152 |       printf (" [%*" PRIx64 "]  \"%s\"\n", digits, (uint64_t) offset,
str);
      |               ^~~~~~
cc1: all warnings being treated as errors

Can you please check that?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug general/24068] readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32
  2019-01-06 15:58 [Bug general/24068] New: readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32 marxin.liska at gmail dot com
@ 2019-01-13 17:02 ` mark at klomp dot org
  2019-01-14 10:26 ` marxin.liska at gmail dot com
  2023-10-06 11:03 ` mark at klomp dot org
  2 siblings, 0 replies; 4+ messages in thread
From: mark at klomp dot org @ 2019-01-13 17:02 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=24068

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-01-13
                 CC|                            |mark at klomp dot org
     Ever confirmed|0                           |1

--- Comment #1 from Mark Wielaard <mark at klomp dot org> ---
This is weird. I cannot replicate with a standard build and gcc (GCC) 9.0.0
20190112 (experimental).

Aha, with -m32. hmmm. Odd.

So the issue seems to be that GCC doesn't realize digits is capped between 4
and 16. We could help with with something like:

diff --git a/src/readelf.c b/src/readelf.c
index 3a73710ff..83b700eee 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -10128,7 +10128,7 @@ print_debug_str_section (Dwfl_Module *dwflmod
__attribute__ ((unused)),
       ++digits;
       tmp >>= 4;
     }
-  digits = MAX (4, digits);
+  digits = MIN (16, MAX (4, digits));

   printf (gettext ("\nDWARF section [%2zu] '%s' at offset %#" PRIx64 ":\n"
                   " %*s  String\n"),

I that the correct fix though? Or is something else going on?
I don't understand why this is -m32 specific.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug general/24068] readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32
  2019-01-06 15:58 [Bug general/24068] New: readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32 marxin.liska at gmail dot com
  2019-01-13 17:02 ` [Bug general/24068] " mark at klomp dot org
@ 2019-01-14 10:26 ` marxin.liska at gmail dot com
  2023-10-06 11:03 ` mark at klomp dot org
  2 siblings, 0 replies; 4+ messages in thread
From: marxin.liska at gmail dot com @ 2019-01-14 10:26 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=24068

Martin Liška <marxin.liska at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=88835

--- Comment #2 from Martin Liška <marxin.liska at gmail dot com> ---
(In reply to Mark Wielaard from comment #1)
> This is weird. I cannot replicate with a standard build and gcc (GCC) 9.0.0
> 20190112 (experimental).
> 
> Aha, with -m32. hmmm. Odd.
> 
> So the issue seems to be that GCC doesn't realize digits is capped between 4
> and 16. We could help with with something like:

Probably.

> 
> diff --git a/src/readelf.c b/src/readelf.c
> index 3a73710ff..83b700eee 100644
> --- a/src/readelf.c
> +++ b/src/readelf.c
> @@ -10128,7 +10128,7 @@ print_debug_str_section (Dwfl_Module *dwflmod
> __attribute__ ((unused)),
>        ++digits;
>        tmp >>= 4;
>      }
> -  digits = MAX (4, digits);
> +  digits = MIN (16, MAX (4, digits));
>  
>    printf (gettext ("\nDWARF section [%2zu] '%s' at offset %#" PRIx64 ":\n"
>                    " %*s  String\n"),
> 
> I that the correct fix though? Or is something else going on?

I can confirm it fixes that.

> I don't understand why this is -m32 specific.

Me neither, so that I created GCC PR for that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug general/24068] readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32
  2019-01-06 15:58 [Bug general/24068] New: readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32 marxin.liska at gmail dot com
  2019-01-13 17:02 ` [Bug general/24068] " mark at klomp dot org
  2019-01-14 10:26 ` marxin.liska at gmail dot com
@ 2023-10-06 11:03 ` mark at klomp dot org
  2 siblings, 0 replies; 4+ messages in thread
From: mark at klomp dot org @ 2023-10-06 11:03 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=24068

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |MOVED

--- Comment #3 from Mark Wielaard <mark at klomp dot org> ---
The GCC bug has been fixed.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88835

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-06 11:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-06 15:58 [Bug general/24068] New: readelf.c:10152:15: error: ‘%*llx’ directive output between 4 and 2147483647 bytes may cause result to exceed ‘INT_MAX’ [-Werror=format-overflow=] with -m32 marxin.liska at gmail dot com
2019-01-13 17:02 ` [Bug general/24068] " mark at klomp dot org
2019-01-14 10:26 ` marxin.liska at gmail dot com
2023-10-06 11:03 ` mark at klomp dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).