ash: fail if 'shift' operand is out of range
authorIngo van Lil <inguin@gmx.de>
Fri, 5 Jan 2018 14:04:23 +0000 (15:04 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 14 Feb 2018 16:38:29 +0000 (17:38 +0100)
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@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c

index dfb7d4d8e5dbbd423005de4b1e03a95f44c9af89..b73a79975de4f6c561738743b86ea062afd3b0e5 100644 (file)
@@ -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++) {