Re: [BUG] regression in builtin echo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 02, 2016 at 09:14:39PM +0800, Herbert Xu wrote:
> Harald van Dijk <harald@xxxxxxxxxxx> wrote:

> > While the original code implementing the echo command was overly 
> > complicated, the simplified version does not do the right thing, as you 
> > noticed.

> Indeed.

> However, we don't need to rewrite the function to fix this.

> ---8<---
> Subject: builtin: Fix echo -n early termination

> The commit 7a784244625d5489c0fc779201c349555dc5f8bc ("[BUILTIN]
> Simplify echo command") broke echo -n by making it always terminate
> after printing the first argument.

> This patch fixes this by only terminating when we have reached
> the end of the arguments.

> Fixes: 7a784244625d ("[BUILTIN] Simplify echo command")
> Reported-by: Luigi Tarenga <luigi.tarenga@xxxxxxxxx>
> Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

> diff --git a/src/bltin/printf.c b/src/bltin/printf.c
> index 1112253..a626cee 100644
> --- a/src/bltin/printf.c
> +++ b/src/bltin/printf.c
> @@ -459,7 +459,7 @@ echocmd(int argc, char **argv)
>  
>  		if (likely(*argv))
>  			nonl += print_escape_str("%s", NULL, NULL, *argv++);
> -		if (nonl > 0)
> +		if (likely((nonl + !*argv) > 1))
>  			break;
>  
>  		c = *argv ? ' ' : '\n';

Unlike Harald van Dijk's patch, the above patch breaks \c. Per POSIX
(XSI option), \c shall cause all characters following it in the
arguments to be ignored (so not only in the argument where \c occurs).
For example:
  echo 'a\cb' c; echo d
shall write "ad" followed by a newline.

-- 
Jilles Tjoelker
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux