glibc/argp
Joseph Myers a3708cf6b0 Avoid use of atoi in some places in libc
This patch is split out of
<https://sourceware.org/pipermail/libc-alpha/2022-December/144122.html>.

atoi has undefined behavior on out-of-range input, which makes it
problematic to use anywhere in glibc that might be processing input
out-of-range for atoi but not specified to produce undefined behavior
for the function calling atoi.  Change some uses of atoi to call
strtol instead; this avoids the undefined behavior, though there is no
guarantee that the overflow handling of strtol is really right in
those places either.  This also serves to avoid localplt test failures
given an installed header redirection for strtol (which means that the
call from the inline atoi implementation doesn't end up at a hidden
alias from libc_hidden_proto).

Certainly, the use of atoi is questionable in argp-help.c (shared with
gnulib, so shouldn't depend on glibc implementation details, and
processing user-provided input), and maybe also in argp-parse.c (I'm
not sure what that code in argp-parse.c is meant to be used for).  I
also changed inet/rexec.c and resolv/res_init.c similarly to use
strtol to avoid such localplt failures, although given those files (in
those versions) are only used in glibc it's not problematic for them
to rely on the specific behavior of glibc's atoi on out-of-range input
(in the absence of compiler optimizations based on the undefined
behavior) in the same way it's problematic for gnulib code to do so.

There may be other uses of atoi (or atol or atoll), in any of glibc's
installed code, for which it would also be appropriate to avoid the
undefined behavior on out-of-range input; this patch only fixes the
specific cases needed to avoid localplt failures.

Tested for x86_64.
2022-12-19 14:45:44 +00:00
..
bits Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-ba.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-eexst.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-fmtstream.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-fmtstream.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-fs-xinl.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-help.c Avoid use of atoi in some places in libc 2022-12-19 14:45:44 +00:00
argp-namefrob.h argp: Remove old includes in !_LIBC case 2022-07-04 15:25:18 +02:00
argp-parse.c Avoid use of atoi in some places in libc 2022-12-19 14:45:44 +00:00
argp-pv.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-pvh.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-test.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp-xinl.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
argp.h Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
bug-argp1.c * posix/wordexp.c (w_addword): Free word if realloc fails and it 2006-05-10 00:03:41 +00:00
bug-argp2.c Add test case for last argp bug. 2010-04-04 11:28:36 -07:00
Makefile configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases 2022-11-01 09:51:06 -03:00
tst-argp1.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-argp2.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
tst-ldbl-argp.c Update copyright dates with scripts/update-copyrights 2022-01-01 11:40:24 -08:00
Versions Update ABI information 2012-01-07 19:23:45 -05:00