Re: [PATCH] left shift of negative value do_binop src/arith_yacc.c:111:12

Harald van Dijk <[email protected]> Thu, 31 Jul 2025 22:50:59 +0100
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On 31/07/2025 19:49, Aleksander Ushakov wrote:
> There is a fix of the problem:
> 
> diff --git a/src/arith_yacc.c b/src/arith_yacc.c
> index 1a087c3..e23060d 100644
> --- a/src/arith_yacc.c
> +++ b/src/arith_yacc.c
> @@ -108,7 +108,9 @@ static intmax_t do_binop(int op, intmax_t a, 
> intmax_t b)
>          case ARITH_SUB:
>                  return a - b;
>          case ARITH_LSHIFT:
> -               return a << b;
> +               if (a < 0)
> +                       yyerror("left shift of negative value");
> +               return (intmax_t)a << b;
>          case ARITH_RSHIFT:
>                  return a >> b;
>          case ARITH_LT:
If other major shells already issued an error here, this change would 
look fine (except again incomplete -- there is a lot more potential to 
trigger sanitizer messages in this file), but as other major shells 
accept this, I think dash should continue to accept this too.

Cheers,
Harald van Dijk