[git commit branch/1_28_stable] ash: fail if 'shift' operand is out of range
Denys Vlasenko
vda.linux at googlemail.com
Wed Feb 14 16:38:29 UTC 2018
commit: https://git.busybox.net/busybox/commit/?id=59675c625d6500a9a0657481321954b0d1f63da9
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/1_28_stable
If the numeric argument passed to ash's 'shift' built-in is greater than
'$#' the command performs no operation and exits successfully. It should
return a non-zero exit code instead:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#shift
This is consistent with bash and hush.
function old new delta
shiftcmd 122 120 -2
Signed-off-by: Ingo van Lil <inguin at gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
shell/ash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/shell/ash.c b/shell/ash.c
index dfb7d4d8e..b73a79975 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10858,7 +10858,7 @@ shiftcmd(int argc UNUSED_PARAM, char **argv)
if (argv[1])
n = number(argv[1]);
if (n > shellparam.nparam)
- n = 0; /* bash compat, was = shellparam.nparam; */
+ return 1;
INT_OFF;
shellparam.nparam -= n;
for (ap1 = shellparam.p; --n >= 0; ap1++) {
More information about the busybox-cvs
mailing list