]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): Diagnose an invalid width option.
authorJim Meyering <jim@meyering.net>
Tue, 28 Aug 2001 08:32:51 +0000 (08:32 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 28 Aug 2001 08:32:51 +0000 (08:32 +0000)
src/fmt.c

index f3c39b757f2030eb619100e345a0fe32d2f25559..f56745a47e7f20a1ec6c65e96e60ebc462f2f883 100644 (file)
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -325,13 +325,16 @@ main (register int argc, register char **argv)
 
   if (argc > 1 && argv[1][0] == '-' && ISDIGIT (argv[1][1]))
     {
+      const char *s = argv[1] + 1;
       max_width = 0;
       /* Old option syntax; a dash followed by one or more digits.
          Move past the number. */
-      for (++argv[1]; ISDIGIT (*argv[1]); ++argv[1])
+      for (; ISDIGIT (*s); ++s)
        {
-         /* FIXME: use strtol to detect overflow.  */
-         max_width = max_width * 10 + *argv[1] - '0';
+         int old_max = max_width;
+         max_width = max_width * 10 + *s - '0';
+         if (INT_MAX / 10 < old_max || max_width < old_max)
+           error (EXIT_FAILURE, 0, _("invalid width option: `%s'"), argv[1]);
        }
       /* Make the options we just parsed invisible to getopt. */
       argv[1] = argv[0];