bug-gawk
[Top][All Lists]
Advanced

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

Re: accessing ENVIRON causes SIGFPE when first var is numeric


From: David Arroyo
Subject: Re: accessing ENVIRON causes SIGFPE when first var is numeric
Date: Wed, 15 Jun 2022 02:05:11 +0200
User-agent: Cyrus-JMAP/3.7.0-alpha0-712-gb9e94258b0-fm-20220610.001-gb9e94258

Thanks for your response!

My distribution does not ship HEAD, it is at version 5.1.0. I reproduced at 
HEAD to demonstrate that the issue is not resolved upstream.

I also did not expect my distribution to set numeric environment variables, but 
I think it's a result you can get accidentally from running your shell with 
`set -a`. If it's not posix compliant I will report it.

Thanks,
David

On Tue, Jun 14, 2022, at 20:35, arnold@skeeve.com wrote:
> Hi.
>
> Thanks for the report.  Your fix is what I would have done; I will
> get it into the code base.
>
> As a general remark, using HEAD from masster, that is, an unreleased
> version, isn't necessarily recommended.  I hope that's not what
> your distribution is shipping but just what you happened to build.
>
> Also, the use of a purely numeric value as an environment variable
> name is at the least against standard practice; it might even
> violate POSIX, but I gather this is what your distribution does
> for you.
>
> In any case, much thanks!
>
> Arnold
>
> "David Arroyo" <david@aqwari.net> wrote:
>
>> Configuration Information [Automatically generated, do not change]:
>> Machine: x86_64
>> OS: linux-gnu
>> Compiler: gcc
>> Compilation CFLAGS: -g -O2 -DNDEBUG
>> uname output: Linux dorcas 5.15.43 #1 SMP 1 x86_64 GNU/Linux
>> Machine Type: x86_64-pc-linux-gnu
>>
>> Gawk Version: 5.1.60 (HEAD)
>>
>> Attestation:
>>         I have read 
>> https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
>>         Yes
>>
>> Description:
>>
>> Since commit 7d19cbd5, if the first environment variable is a
>> number, gawk will treat ENVIRON as a cint_array instead of a
>> str_array. You can reproduce this with the following command
>> line:
>>
>>      env -i \
>>        $(which env) 0=foo x=bar \
>>        $(which gawk) 'BEGIN { ENVIRON["x"] }' /dev/null
>>
>> Will yield the error:
>>
>>      gawk: cmd. line:1: fatal: floating point exception
>>
>>  at str_array.c:607 
>>
>> And I can see from a debugger that after the first iteration
>> of load_environ, ENVIRON_node->array_funcs becomes
>> cint_array_func. This issue does not occure when using
>> the --posix flag.
>>
>> I ran into this error on my personal computer running GNU
>> Guix, where the first variable in my environment is
>>
>>      0=/home/me/bin/startw
>>
>> I am not sure if this is common, as I do not see such an
>> env var on a debian 10 system I had handy, and I have not
>> tracked down what exactly sets that variable. But it seems
>> undesirable for variations in user environment variables
>> to trigger a crash.
>>
>> Fix:
>>
>> The patch below hardcodes ENVIRON_node to use the
>> str_array_func family of functions. I don't know if that is
>> the best way to fix the issue, but it helps to illustrate what's
>> happening. I could not reproduce this issue using an 
>> arbitrary array.
>>
>> ---
>>  main.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/main.c b/main.c
>> index 2cdd1e2d..3f48ddfb 100644
>> --- a/main.c
>> +++ b/main.c
>> @@ -922,6 +922,7 @@ load_environ()
>>      been_here = true;
>>
>>      ENVIRON_node = install_symbol(estrdup("ENVIRON", 7), Node_var_array);
>> +    ENVIRON_node->array_funcs = &str_array_func;
>>      for (i = 0; environ[i] != NULL; i++) {
>>              static char nullstr[] = "";
>>
>> --
>>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]