diff options
author | dds <dds@FreeBSD.org> | 2005-08-04 10:05:12 +0000 |
---|---|---|
committer | dds <dds@FreeBSD.org> | 2005-08-04 10:05:12 +0000 |
commit | 738048010904a58ab678318e90794fee8679ec5d (patch) | |
tree | a399f6b7aea5fc34dcdca2143ab087ae29030265 | |
parent | 149e4a2dca6ec642808fed92c56e2c69a4f63110 (diff) | |
download | FreeBSD-src-738048010904a58ab678318e90794fee8679ec5d.zip FreeBSD-src-738048010904a58ab678318e90794fee8679ec5d.tar.gz |
Bug fix: a numeric flag specification in the substitute command would
cause the next substitute flag to be ignored.
While working at it, detect and report overflows.
Reported by: Jingsong Liu
MFC after: 1 week
-rw-r--r-- | usr.bin/sed/compile.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c index ce8a46e..14ef81b 100644 --- a/usr.bin/sed/compile.c +++ b/usr.bin/sed/compile.c @@ -547,6 +547,7 @@ static char * compile_flags(char *p, struct s_subst *s) { int gn; /* True if we have seen g or n */ + unsigned long nval; char wfile[_POSIX2_LINE_MAX + 1], *q; s->n = 1; /* Default */ @@ -577,8 +578,13 @@ compile_flags(char *p, struct s_subst *s) errx(1, "%lu: %s: more than one number or 'g' in substitute flags", linenum, fname); gn = 1; - /* XXX Check for overflow */ - s->n = (int)strtol(p, &p, 10); + errno = 0; + nval = strtol(p, &p, 10); + if (errno == ERANGE || nval > INT_MAX) + errx(1, +"%lu: %s: overflow in the 'N' substitute flag", linenum, fname); + s->n = nval; + p--; break; case 'w': p++; |