hush: fix a corner case of empty "do \n done" structure

The structure is:

    while cmd; do
    done

bash doesn't accept it at all. We were accepting it but execution
was buggy.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2011-05-31 17:35:45 +02:00
parent 14f55538f0
commit 00ae989ee5
3 changed files with 9 additions and 1 deletions

View File

@ -7498,7 +7498,10 @@ static int run_list(struct pipe *pi)
#endif #endif
#if ENABLE_HUSH_LOOPS #if ENABLE_HUSH_LOOPS
/* Beware of "while false; true; do ..."! */ /* Beware of "while false; true; do ..."! */
if (pi->next && pi->next->res_word == RES_DO) { if (pi->next
&& (pi->next->res_word == RES_DO || pi->next->res_word == RES_DONE)
/* (the second check above is needed for "while ...; do \n done" case) */
) {
if (rword == RES_WHILE) { if (rword == RES_WHILE) {
if (rcode) { if (rcode) {
/* "while false; do...done" - exitcode 0 */ /* "while false; do...done" - exitcode 0 */

View File

@ -0,0 +1 @@
OK:0

View File

@ -0,0 +1,4 @@
while false; do
# bash will require at least ":" here...
done
echo OK:$?