[PATCH v1 1/1] readelf: invalid error message triggered when last tag is an empty string

Richard Earnshaw Richard.Earnshaw@arm.com
Wed Jun 18 10:47:26 GMT 2025


On 18/06/2025 11:42, Jan Beulich wrote:
> On 18.06.2025 12:27, Matthieu Longo wrote:
>> Disclaimer: this issue cannot occur with Object Attributes v1 (OAv1) because
>> a value of '\0' (empty string) for a tag with a string value is considered
>> as the default value for the attribute, and consequently is eliminated
>> from the output object during the serialization.
>>
>> In the context of OAv2 [1], an empty string is a valid value for a string
>> attribute tag, and can be saved as a tag might not have a default value.
> 
> Is there a word (or more) missing in the latter part of this sentence?
> 
>> --- a/binutils/readelf.c
>> +++ b/binutils/readelf.c
>> @@ -17779,12 +17779,14 @@ display_tag_value (signed int tag,
>>     else if (tag & 1)
>>       {
>>         /* PR 17531 file: 027-19978-0.004.  */
>> -      size_t maxlen = (end - p) - 1;
>> +      size_t maxlen = end - p;
>>   
>>         putchar ('"');
>>         if (maxlen > 0)
>>   	{
>> -	  print_symbol_name ((int) maxlen, (const char *) p);
>> +	  maxlen -= 1; /* Remove \0 from the character count.  */
> 
> How do you know it's \0 that sits there?

It's (supposed to be) a NTBS (null-terminated byte string).  So either 
it's \0 or it's a corrupt file.

> 
>> +	  if (maxlen > 0) /* Don't try to print an empty string.  */
>> +	    print_symbol_name ((int) maxlen, (const char *) p);
> 
> Am I understanding correctly that for OAv2 this will then need further
> modifying, as (if I understand the description correctly) an empty
> string there is not the same as no tag at all.
> 
> Jan



More information about the Binutils mailing list