[PATCH 4/7] smbios: string table always needs two terminating NUL bytes

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Wed Jan 31 19:02:40 CET 2024


On 31.01.24 18:15, Matthias Brugger wrote:
> On Mon, Jan 29, 2024 at 10:04:50PM +0100, Heinrich Schuchardt wrote:
>> The string section of the different SMBIOS structures is always terminated
>> by two NUL bytes even if there is no string at all. This is described in
>> section 6.1.3 "Text string" of the SMBIOS 3.7.0 specification.
>>
>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> 
> I send the very same patch some years ago [1], unfortunately it got
> somehow lost. Happy to see you trying to fix the same problem, so:
> Reviewed-by: Matthias Brugger <mbrugger at suse.com>
> 
> 
> [1] https://patchwork.ozlabs.org/project/uboot/patch/20210406090435.19357-1-matthias.bgg@kernel.org/

Thanks for the pointer. I assume not answering Simon's question lead to 
your patch not being merged.

To answer it:

 >> But where are the \0 bytes
 >> actually written? Perhaps that should be in smbios_set_eos()?

We have defined SMBIOS_STRUCT_EOS_BYTES as 2 and we have an array
char eos[SMBIOS_STRUCT_EOS_BYTES];
at the end of each SMBIOS structure.

We call memset(t, 0, sizeof(struct smbios_typeX)); for each table.
This is enough to ensure two zero bytes exist if there are no strings.

Best regards

Heinrich

> 
>> ---
>>   lib/smbios.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/lib/smbios.c b/lib/smbios.c
>> index 7bd9805fec0..81908e89610 100644
>> --- a/lib/smbios.c
>> +++ b/lib/smbios.c
>> @@ -311,6 +311,9 @@ int smbios_update_version(const char *version)
>>    */
>>   static int smbios_string_table_len(const struct smbios_ctx *ctx)
>>   {
>> +	/* If the structure contains no string it is followed by two NUL bytes */
>> +	if (ctx->next_ptr == ctx->eos)
>> +		return 2;
>>   	/* Allow for the final \0 after all strings */
>>   	return (ctx->next_ptr + 1) - ctx->eos;
>>   }
>> -- 
>> 2.43.0



More information about the U-Boot mailing list