diff options
author | jilles <jilles@FreeBSD.org> | 2014-07-12 21:54:11 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2014-07-12 21:54:11 +0000 |
commit | 9af633c667c4ce3e8313accf6ff0812a0efbcb35 (patch) | |
tree | 4478df8c6a08c9776035584a7382dc7266b7b9f3 /bin/sh/expand.c | |
parent | 2d9c44fabaead99fab9b88e5dfe1e9dbbf7c38b2 (diff) | |
download | FreeBSD-src-9af633c667c4ce3e8313accf6ff0812a0efbcb35.zip FreeBSD-src-9af633c667c4ce3e8313accf6ff0812a0efbcb35.tar.gz |
sh: Correctly handle positional parameters beyond INT_MAX on 64-bit systems.
Currently, there can be no more than INT_MAX positional parameters. Make
sure to treat all higher ones as unset to avoid incorrect results and
crashes.
On 64-bit systems, our atoi() takes the low 32 bits of the strtol() and
sign-extends them.
On 32-bit systems, the call to atoi() returned INT_MAX for too high values
and there is not enough address space for so many positional parameters, so
there was no issue.
Diffstat (limited to 'bin/sh/expand.c')
-rw-r--r-- | bin/sh/expand.c | 6 |
1 files changed, 4 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) |