]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): Check for overflow in tabstop values
authorJim Meyering <jim@meyering.net>
Tue, 11 Jan 2005 16:53:24 +0000 (16:53 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 11 Jan 2005 16:53:24 +0000 (16:53 +0000)
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'.

src/unexpand.c

index 1341e437cc8ba88b021f5b81e984663d5ef57139..60a3f1d61f3f14c46474122dfde2e01435bf6675 100644 (file)
@@ -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;
        }