mirror of
https://github.com/mirror/make.git
synced 2025-01-13 22:00:08 +08:00
* src/arscan.c (parse_int): Fix integer overflow test
Use intprops.h macros rather than trying to detect integer overflow by hand, and doing it incorrectly. Example of incorrect behavior: if val == 3689348814741910323, base == 10, UINTMAX_WIDTH == 64, and *ptr == '0' then (val*base)+(*ptr-'0') yields 18446744073709551614 which is greater than val even though overflow has occurred. Fortunately this bug could not be triggered on GNU/Linux hosts, although it may be possible on platforms (if any) where struct ar_hdr has members so large that they can represent integers that do not fit int uintmax_t.
This commit is contained in:
parent
f289ece6cf
commit
61ee4578f5
12
src/arscan.c
12
src/arscan.c
@ -395,16 +395,12 @@ parse_int (const char *ptr, const size_t len, const int base, uintmax_t max,
|
|||||||
|
|
||||||
while (ptr < ep && *ptr != ' ')
|
while (ptr < ep && *ptr != ' ')
|
||||||
{
|
{
|
||||||
uintmax_t nv;
|
if (*ptr < '0' || *ptr > maxchar
|
||||||
|
|| INT_MULTIPLY_WRAPV (val, base, &val)
|
||||||
if (*ptr < '0' || *ptr > maxchar)
|
|| INT_ADD_WRAPV (val, *ptr - '0', &val)
|
||||||
|
|| val > max)
|
||||||
OSSS (fatal, NILF,
|
OSSS (fatal, NILF,
|
||||||
_("invalid %s for archive %s member %s"), type, archive, name);
|
_("invalid %s for archive %s member %s"), type, archive, name);
|
||||||
nv = (val * base) + (*ptr - '0');
|
|
||||||
if (nv < val || nv > max)
|
|
||||||
OSSS (fatal, NILF,
|
|
||||||
_("invalid %s for archive %s member %s"), type, archive, name);
|
|
||||||
val = nv;
|
|
||||||
++ptr;
|
++ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user