From: Jim Meyering Date: Tue, 28 Aug 2001 08:32:51 +0000 (+0000) Subject: (main): Diagnose an invalid width option. X-Git-Tag: TEXTUTILS-2_0_15~266 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ac5676264c5659004762cefd0f810451ad9ca60;p=thirdparty%2Fcoreutils.git (main): Diagnose an invalid width option. --- diff --git a/src/fmt.c b/src/fmt.c index f3c39b757f..f56745a47e 100644 --- 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];