[12/19] RISC-V: riscv_set_arch() can fail

Message ID d39a0dc0-110f-400a-9473-090ddf96efa2@suse.com
State New
Headers
Series RISC-V: assorted fixes and (hopefully) improvements |

Commit Message

Jan Beulich April 21, 2026, 11:54 a.m. UTC
  In that case neither riscv_rps_as.subset_list nor file_arch_str would be
set, yet the NULL pointers would be happily passed into functions not
expecting such.
  

Comments

Simon Richter April 21, 2026, 1 p.m. UTC | #1
Hi,

On 4/21/26 8:54 PM, Jan Beulich wrote:

> In that case neither riscv_rps_as.subset_list nor file_arch_str would be
> set, yet the NULL pointers would be happily passed into functions not
> expecting such.

> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -345,7 +345,9 @@ riscv_set_arch (const char *s)
>       {
>         as_bad (_("the architecture string of -march and elf architecture "
>   		"attributes cannot be empty"));
> -      return;
> +      if (file_arch_str != NULL)
> +	return;
> +      s = DEFAULT_RISCV_ARCH_WITH_EXT;
>       }

Am I reading this correctly that this is still an error, but it avoids a 
follow-up NULL pointer dereference?

This is the diagnostic that allowed us to find a bug in ghdl (the vhdl1 
frontend does not set the arch string).

    Simon
  
Jan Beulich April 21, 2026, 1:02 p.m. UTC | #2
On 21.04.2026 15:00, Simon Richter wrote:
> On 4/21/26 8:54 PM, Jan Beulich wrote:
> 
>> In that case neither riscv_rps_as.subset_list nor file_arch_str would be
>> set, yet the NULL pointers would be happily passed into functions not
>> expecting such.
> 
>> --- a/gas/config/tc-riscv.c
>> +++ b/gas/config/tc-riscv.c
>> @@ -345,7 +345,9 @@ riscv_set_arch (const char *s)
>>       {
>>         as_bad (_("the architecture string of -march and elf architecture "
>>   		"attributes cannot be empty"));
>> -      return;
>> +      if (file_arch_str != NULL)
>> +	return;
>> +      s = DEFAULT_RISCV_ARCH_WITH_EXT;
>>       }
> 
> Am I reading this correctly that this is still an error, but it avoids a 
> follow-up NULL pointer dereference?

Yes, as visible from patch context the as_bad() won't be bypassed.

Jan
  

Patch

--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -345,7 +345,9 @@  riscv_set_arch (const char *s)
     {
       as_bad (_("the architecture string of -march and elf architecture "
 		"attributes cannot be empty"));
-      return;
+      if (file_arch_str != NULL)
+	return;
+      s = DEFAULT_RISCV_ARCH_WITH_EXT;
     }
 
   if (riscv_rps_as.subset_list == NULL)