Wolfgang Denk writes:
authorEric Andersen <andersen@codepoet.org>
Mon, 12 Apr 2004 21:41:29 +0000 (21:41 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 12 Apr 2004 21:41:29 +0000 (21:41 -0000)
He,

there is a bug in HUSH's handling of "if" / "elif" commands:

        $  if true
        > then
        > echo 1
        > elif
        > true
        > then
        > echo 2
        > elif
        > true
        > then
        > echo 3
        > else
        > echo 4
        > fi
        1
        2
        3
        $

The same bug exists in all versions of HUSH from BB v0.60.x up to and
including v1.00-pre9. The attached patch fixes this:

        $ if true
        > then
        > echo 1
        > elif
        > true
        > then
        > echo 2
        > elif
        > true
        > then
        > echo 3
        > else
        > echo 4
        > fi
        1
        $

Best regards,

Wolfgang Denk

shell/hush.c

index 8f4cc9780f8795f6927bd3e523ac8363a78a9ade..6d31cdca57cf26793a59914d18f55cee02e0371e 100644 (file)
@@ -1557,7 +1557,7 @@ static int run_list_real(struct pipe *pi)
                if (rmode == RES_THEN || rmode == RES_ELSE) if_code = next_if_code;
                if (rmode == RES_THEN &&  if_code) continue;
                if (rmode == RES_ELSE && !if_code) continue;
-               if (rmode == RES_ELIF && !if_code) continue;
+               if (rmode == RES_ELIF && !if_code) break;
                if (rmode == RES_FOR && pi->num_progs) {
                        if (!list) {
                                /* if no variable values after "in" we skip "for" */