diff options
-rw-r--r-- | bin/sh/expand.c | 6 | ||||
-rw-r--r-- | bin/sh/tests/parameters/Makefile | 1 | ||||
-rw-r--r-- | bin/sh/tests/parameters/positional5.0 | 14 |
3 files changed, 19 insertions, 2 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c index b8ef5ea..15afc9c 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -846,9 +846,11 @@ varisset(const char *name, int nulok) } } else if (is_digit(*name)) { char *ap; - int num = atoi(name); + long num; - if (num > shellparam.nparam) + errno = 0; + num = strtol(name, NULL, 10); + if (errno != 0 || num > shellparam.nparam) return 0; if (num == 0) diff --git a/bin/sh/tests/parameters/Makefile b/bin/sh/tests/parameters/Makefile index 2574226..da49d14 100644 --- a/bin/sh/tests/parameters/Makefile +++ b/bin/sh/tests/parameters/Makefile @@ -15,6 +15,7 @@ FILES+= positional1.0 FILES+= positional2.0 FILES+= positional3.0 FILES+= positional4.0 +FILES+= positional5.0 FILES+= pwd1.0 FILES+= pwd2.0 diff --git a/bin/sh/tests/parameters/positional5.0 b/bin/sh/tests/parameters/positional5.0 new file mode 100644 index 0000000..eeaaba5 --- /dev/null +++ b/bin/sh/tests/parameters/positional5.0 @@ -0,0 +1,14 @@ +# $FreeBSD$ + +i=1 +r=0 +while [ $i -lt $((0x100000000)) ]; do + t= + eval t=\${$i-x} + case $t in + x) ;; + *) echo "Problem with \${$i}" >&2; r=1 ;; + esac + i=$((i + 0x10000000)) +done +exit $r |