smbios: Fix table when no string is present
PATCH v2 1/1 smbios: Fix table when no string is present
From: Matthias Brugger <[email protected]>
When no string is present in a table, next_ptr points to the same location as eos. When calculating the string table length, we would only reserve one \0. By spec a SMBIOS table has to end with two \0\0 when no strings a present.
---
Changes in v2:
- check in smbios_string_table_len if no string present and return value accordingly
lib/smbios.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/smbios.c +4 -0
@@ -191,6 +191,10 @@ int smbios_update_version(const char *version)*/ static int smbios_string_table_len (const struct smbios_ctx *ctx) { +/* In case no string is defined we have to return two \0 */ +if (ctx->next_ptr == ctx->eos) +return 2 ; +/* Allow for the final \0 after all strings */ return (ctx->next_ptr +1 ) - ctx->eos; }
Signature · 1 line
2.30.2
PATCH v2 1/1 smbios: Fix table when no string is present
Hi Matthias,
Quoted 8 lines · On Tue, 6 Apr 2021 at 21:04, <[email protected]> wrote:
From: Matthias Brugger <[email protected]>
When no string is present in a table,
next_ptrpoints to the same location as eos. When calculating the string table length, we would only reserve one \0. By spec a SMBIOS table has to end with two \0\0 when no strings a present.
Quoted 7 lines
Signed-off-by Matthias Brugger <[email protected]>---
Changes in v2:
- check insmbios_string_table_lenif no string present and return value accordingly
This looks like a better idea to me. But where are the \0 bytes actually written? Perhaps that should be in smbios_set_eos()?
Quoted 20 lines
lib/smbios.c | 4 ++++ 1 file changed, 4 insertions(+)lib/smbios.c +4
-1@@ -191,6 +191,10 @@ int smbios_update_version(const char *version)*/ static int smbios_string_table_len (const struct smbios_ctx *ctx) { +/* In case no string is defined we have to return two \0 */ +if (ctx->next_ptr == ctx->eos) +return 2 ; +/* Allow for the final \0 after all strings */ return (ctx->next_ptr +1 ) - ctx->eos; } --
Quoted 2 lines
2.30.2
Regards,
Simon
Quoted 13 lines · Simon Glass
Hi Matthias,
Quoted 10 lines · On Tue, 6 Apr 2021 at 21:04, <[email protected]> wrote:
From: Matthias Brugger <[email protected]>
When no string is present in a table,
next_ptrpoints to the same location as eos. When calculating the string table length, we would only reserve one \0. By spec a SMBIOS table has to end with two \0\0 when no strings a present.Signed-off-by Matthias Brugger <[email protected]>
Quoted 8 lines
Quoted 5 lines
---
Changes in v2:
- check insmbios_string_table_lenif no string present and return value accordinglyThis looks like a better idea to me. 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.
Quoted 27 lines
Quoted 21 lines
lib/smbios.c | 4 ++++ 1 file changed, 4 insertions(+)lib/smbios.c +4
-1@@ -191,6 +191,10 @@ int smbios_update_version(const char *version)*/ static int smbios_string_table_len (const struct smbios_ctx *ctx) { +/* In case no string is defined we have to return two \0 */ +if (ctx->next_ptr == ctx->eos) +return 2 ; +/* Allow for the final \0 after all strings */ return (ctx->next_ptr +1 ) - ctx->eos; } --Quoted 2 lines
2.30.2
Regards,
Simon