ash: allow popredir to be called if the stack is empty

If /tmp/test.sh is a script that tries to run a second script which
happens to be non-executable this:

   command . /tmp/test.sh

causes a seg fault.

This is because clearredir is called in the error path to clear the
stack of redirections.  The normal path then calls popredir, but popredir
fails when the stack is empty.

Reported-by: Bastian Bittorf <bittorf@bluebottle.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston 2015-10-30 19:07:37 +00:00 committed by Denys Vlasenko
parent 8c55dc79a7
commit 95650a86d1

View File

@ -5409,7 +5409,7 @@ popredir(int drop, int restore)
struct redirtab *rp;
int i;
if (--g_nullredirs >= 0)
if (--g_nullredirs >= 0 || redirlist == NULL)
return;
INT_OFF;
rp = redirlist;