From: Jim Meyering Date: Tue, 11 Jan 2005 16:53:24 +0000 (+0000) Subject: (main): Check for overflow in tabstop values X-Git-Tag: CPPI-1_12~1633 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c2fed1cc190243e79f4b52c8f6de3f67ec1936e3;p=thirdparty%2Fcoreutils.git (main): Check for overflow in tabstop values specified via the obsolete form. E.g., now this command fails: _POSIX2_VERSION=1 ./unexpand -$(echo '2^64+1'|bc) Before it would act like `_POSIX2_VERSION=1 ./unexpand -1'. --- diff --git a/src/unexpand.c b/src/unexpand.c index 1341e437cc..60a3f1d61f 100644 --- a/src/unexpand.c +++ b/src/unexpand.c @@ -518,7 +518,12 @@ main (int argc, char **argv) tabval = 0; have_tabval = true; } - tabval = tabval * 10 + c - '0'; + { + uintmax_t new_t = tabval * 10 + c - '0'; + if (UINTMAX_MAX / 10 < tabval || new_t < tabval * 10) + error (EXIT_FAILURE, 0, _("tab stop value is too large")); + tabval = new_t; + } obsolete_tablist = true; break; }