summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-23 06:57:57 +0000
committerJim Meyering <jim@meyering.net>2003-07-23 06:57:57 +0000
commit6315f15a2371f5936dd6d34bb828f985cd8d9659 (patch)
tree452e3dcae1de47877ba38b2cd8250fb91126c138 /src
parent496c3add2bbe1b8d47e4d5112eb7d4303ac5ef8b (diff)
downloadcoreutils-6315f15a2371f5936dd6d34bb828f985cd8d9659.tar.xz
(parse_tabstops): Detect overflow in tabstop sizes.
Diffstat (limited to 'src')
-rw-r--r--src/expand.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/expand.c b/src/expand.c
index 530b1d4fd..1cc7f754b 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -42,6 +42,8 @@
#include "closeout.h"
#include "error.h"
#include "posixver.h"
+#include "quote.h"
+#include "xstrndup.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "expand"
@@ -151,9 +153,11 @@ add_tabstop (int tabval)
to the list of tabstops. */
static void
-parse_tabstops (char *stops)
+parse_tabstops (char const *stops)
{
int tabval = -1;
+ char const *num_start IF_LINT (= NULL);
+ int fail = 0;
for (; *stops; stops++)
{
@@ -165,13 +169,36 @@ parse_tabstops (char *stops)
else if (ISDIGIT (*stops))
{
if (tabval == -1)
- tabval = 0;
- tabval = tabval * 10 + *stops - '0';
+ {
+ tabval = 0;
+ num_start = stops;
+ }
+ {
+ /* Detect overflow. */
+ int prev = tabval;
+ tabval = tabval * 10 + *stops - '0';
+ if (tabval < prev)
+ {
+ size_t len = strspn (num_start, "0123456789");
+ char *bad_num = xstrndup (num_start, len);
+ error (0, 0, _("tab stop is too large %s"), quote (bad_num));
+ fail = 1;
+ stops = num_start + len - 1;
+ }
+ }
}
else
- error (EXIT_FAILURE, 0, _("tab size contains an invalid character"));
+ {
+ error (0, 0, _("tab size contains invalid character(s): %s"),
+ quote (stops));
+ fail = 1;
+ break;
+ }
}
+ if (fail)
+ exit (EXIT_FAILURE);
+
add_tabstop (tabval);
}