diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2017-11-11 12:56:00 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2017-11-11 12:56:00 +0000 |
commit | 4ee58763a961112fcf6fc93ce2c8b61a8ca65893 (patch) | |
tree | 9e6b8682acfc581626c066d4e4f35bda61f61d5f /usr.bin | |
parent | a0192abaa3b23ffb9fd8d66743b33ba0e6535d78 (diff) |
replace sloppy parsing of numeric values with strtonum (incr, decr, divert)
still use integers, so use the natural bounds for these.
POSIX says m4 should error when these use non numeric values, and now they
do.
okay millert@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/m4/eval.c | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 8b277a2e09d..bbaf23c697b 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.76 2017/10/23 15:21:19 espie Exp $ */ +/* $OpenBSD: eval.c,v 1.77 2017/11/11 12:55:59 espie Exp $ */ /* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ /* @@ -120,6 +120,7 @@ void expand_builtin(const char *argv[], int argc, int td) { int c, n; + const char *errstr; int ac; static int sysval = 0; @@ -175,18 +176,19 @@ expand_builtin(const char *argv[], int argc, int td) { int base = 10; int maxdigits = 0; - const char *errstr; if (argc > 3) { base = strtonum(argv[3], 2, 36, &errstr); if (errstr) { - m4errx(1, "expr: base %s invalid.", argv[3]); + m4errx(1, "expr: base is %s: %s.", + errstr, argv[3]); } } if (argc > 4) { maxdigits = strtonum(argv[4], 0, INT_MAX, &errstr); if (errstr) { - m4errx(1, "expr: maxdigits %s invalid.", argv[4]); + m4errx(1, "expr: maxdigits is %s: %s.", + errstr, argv[4]); } } if (argc > 2) @@ -225,8 +227,13 @@ expand_builtin(const char *argv[], int argc, int td) * doincr - increment the value of the * argument */ - if (argc > 2) - pbnum(atoi(argv[2]) + 1); + if (argc > 2) { + n = strtonum(argv[2], INT_MIN, INT_MAX-1, &errstr); + if (errstr != NULL) + m4errx(1, "incr: argument is %s: %s.", + errstr, argv[2]); + pbnum(n + 1); + } break; case DECRTYPE: @@ -234,8 +241,13 @@ expand_builtin(const char *argv[], int argc, int td) * dodecr - decrement the value of the * argument */ - if (argc > 2) - pbnum(atoi(argv[2]) - 1); + if (argc > 2) { + n = strtonum(argv[2], INT_MIN+1, INT_MAX, &errstr); + if (errstr) + m4errx(1, "decr: argument is %s: %s.", + errstr, argv[2]); + pbnum(n - 1); + } break; case SYSCTYPE: @@ -336,12 +348,18 @@ expand_builtin(const char *argv[], int argc, int td) break; case DIVRTYPE: - if (argc > 2 && (n = atoi(argv[2])) != 0) - dodiv(n); - else { - active = stdout; - oindex = 0; + if (argc > 2) { + n = strtonum(argv[2], INT_MIN, INT_MAX, &errstr); + if (errstr) + m4errx(1, "divert: argument is %s: %s.", + errstr, argv[2]); + if (n != 0) { + dodiv(n); + break; + } } + active = stdout; + oindex = 0; break; case UNDVTYPE: |