diff mbox

[U-Boot,3/4] Fix hush to give the correct return code for a simple command

Message ID 1400901095-29391-4-git-send-email-sjg@chromium.org
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass May 24, 2014, 3:11 a.m. UTC
When a simple command like 'false' is provided, hush should return the
result of that command. However, hush only does this if the
FLAG_EXIT_FROM_LOOP flag is provided. Without this flag, hush will
happily execute the empty string command immediate after 'false' and
then return a success code.

This behaviour does not seem very useful, and requiring the flag also
seems wrong, since it means that hush will execute only the first command
in a sequence.

Add a check for empty string and fall out of the loop in that case. That
at least fixes the simple command case. This is a change in behaviour but
it is unlikely that the old behaviour would be considered correct in any
case.

Reported-by: Stefan Herbrechtsmeier <stefan@herbrechtsmeier.net>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/hush.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Stefan Herbrechtsmeier May 25, 2014, 8:08 a.m. UTC | #1
Am 24.05.2014 05:11, schrieb Simon Glass:

> When a simple command like 'false' is provided, hush should return the
> result of that command. However, hush only does this if the
> FLAG_EXIT_FROM_LOOP flag is provided. Without this flag, hush will
> happily execute the empty string command immediate after 'false' and
> then return a success code.
>
> This behaviour does not seem very useful, and requiring the flag also
> seems wrong, since it means that hush will execute only the first command
> in a sequence.
>
> Add a check for empty string and fall out of the loop in that case. That
> at least fixes the simple command case. This is a change in behaviour but
> it is unlikely that the old behaviour would be considered correct in any
> case.
>
> Reported-by: Stefan Herbrechtsmeier <stefan@herbrechtsmeier.net>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   common/hush.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/common/hush.c b/common/hush.c
> index 5b43224..7a16795 100644
> --- a/common/hush.c
> +++ b/common/hush.c
> @@ -3218,7 +3218,9 @@ static int parse_stream_outer(struct in_str *inp, int flag)
>   			free_pipe_list(ctx.list_head,0);
>   		}
>   		b_free(&temp);
> -	} while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP));   /* loop on syntax errors, return on EOF */
> +	/* loop on syntax errors, return on EOF */
> +	} while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP) &&
> +		(inp->peek != static_peek || b_peek(inp)));
>   #ifndef __U_BOOT__
>   	return 0;
>   #else
>
Tested-by: Stefan Herbrechtsmeier<stefan@herbrechtsmeier.net>
diff mbox

Patch

diff --git a/common/hush.c b/common/hush.c
index 5b43224..7a16795 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -3218,7 +3218,9 @@  static int parse_stream_outer(struct in_str *inp, int flag)
 			free_pipe_list(ctx.list_head,0);
 		}
 		b_free(&temp);
-	} while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP));   /* loop on syntax errors, return on EOF */
+	/* loop on syntax errors, return on EOF */
+	} while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP) &&
+		(inp->peek != static_peek || b_peek(inp)));
 #ifndef __U_BOOT__
 	return 0;
 #else