smbios: Fix table when no string is present
PATCH 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.
---
lib/smbios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/smbios.c +1 -1
@@ -153,7 +153,7 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)static void smbios_set_eos (struct smbios_ctx *ctx,char *eos) { ctx->eos = eos; - ctx->next_ptr = eos; + ctx->next_ptr = eos +1 ; ctx->last_str =NULL ; }
Signature · 1 line
2.30.2
PATCH 1/1 smbios: Fix table when no string is present
Hi Matthias,
Quoted 8 lines · On Thu, 18 Mar 2021 at 00:30, <[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 6 lines
Signed-off-by Matthias Brugger <[email protected]>---
lib/smbios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
There is a bug here but I don't think this is right fix. I remember worrying about this, making the same change as you did, reverting it and then forgetting about it :-( It has no tests.
You are effectively changing the definition of next_ptr here:
* @next_ptr: pointer to the start of the next string to be added. When the
* table is not empty, this points to the byte after the \0 of the
* previous string.
(there is a typo in that in the code)
I think that breaks adding new strings.
Can you instead change smbios_string_table_len() to add 2?
Quoted 15 lines
lib/smbios.c +1
-2@@ -153,7 +153,7 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)static void smbios_set_eos (struct smbios_ctx *ctx,char *eos) { ctx->eos = eos; - ctx->next_ptr = eos; + ctx->next_ptr = eos +1 ; ctx->last_str =NULL ; } --
Quoted 2 lines
2.30.2
Regards,
Simon
PATCH 1/1 smbios: Fix table when no string is present
Quoted 22 lines · Simon Glass
Hi Matthias,
Quoted 8 lines · On Thu, 18 Mar 2021 at 00:30, <[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 6 lines
Signed-off-by Matthias Brugger <[email protected]>---
lib/smbios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)There is a bug here but I don't think this is right fix. I remember worrying about this, making the same change as you did, reverting it and then forgetting about it :-( It has no tests.
Quoted 6 lines
You are effectively changing the definition of
next_ptrhere:* @next_ptr: pointer to the start of the next string to be added. When the
* table is not empty, this points to the byte after the \0 of the
* previous string.
That's true.
Quoted 4 lines
(there is a typo in that in the code)
I think that breaks adding new strings.
Well it doesn't because when adding a new string, ctx->next_ptr gets overwritten [1]. It is only used to calculate the lenght of the string in smbios_string_table_len() to calculate the size of the table [2]. But yes it's not the obvious way to handle the case when no string is present.
Quoted 2 lines
Can you instead change
smbios_string_table_len()to add 2?
Do you mean returning 2 when no string is present (ctx->next_ptr == ctx->eos)?
Adding 2 will break the case when we have a string present, as a string already finishes with '\0' and we only need a second '\0'.
Regards,
Matthias
[1] https://source.denx.de/u-boot/u-boot/-/blob/master/lib/smbios.c#L95
[2] https://source.denx.de/u-boot/u-boot/-/blob/master/lib/smbios.c#L196
Quoted 21 lines
Quoted 15 lines
lib/smbios.c +1
-2@@ -153,7 +153,7 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)static void smbios_set_eos (struct smbios_ctx *ctx,char *eos) { ctx->eos = eos; - ctx->next_ptr = eos; + ctx->next_ptr = eos +1 ; ctx->last_str =NULL ; } --Quoted 2 lines
2.30.2
Regards,
Simon
PATCH 1/1 smbios: Fix table when no string is present
Hi Matthias,
Quoted 45 lines · Matthias Brugger
Quoted 22 lines · Simon Glass
Hi Matthias,
Quoted 8 lines · On Thu, 18 Mar 2021 at 00:30, <[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 6 lines
Signed-off-by Matthias Brugger <[email protected]>---
lib/smbios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)There is a bug here but I don't think this is right fix. I remember worrying about this, making the same change as you did, reverting it and then forgetting about it :-( It has no tests.
Quoted 6 lines
You are effectively changing the definition of
next_ptrhere:* @next_ptr: pointer to the start of the next string to be added. When the
* table is not empty, this points to the byte after the \0 of the
* previous string.That's true.
Quoted 4 lines
(there is a typo in that in the code)
I think that breaks adding new strings.
Well it doesn't because when adding a new string,
ctx->next_ptrgets overwritten [1]. It is only used to calculate the lenght of the string insmbios_string_table_len()to calculate the size of the table [2]. But yes it's not the obvious way to handle the case when no string is present.
Quoted 7 lines
Quoted 2 lines
Can you instead change
smbios_string_table_len()to add 2?Do you mean returning 2 when no string is present (
ctx->next_ptr==ctx->eos)?Adding 2 will break the case when we have a string present, as a string already finishes with '\0' and we only need a second '\0'.
Oh dear, this is complicated. I think we need to add a few unit tests. Do you have time to try that?
Regards,
Simon
Quoted 28 lines
Regards,
Matthias[1] https://source.denx.de/u-boot/u-boot/-/blob/master/lib/smbios.c#L95
[2] https://source.denx.de/u-boot/u-boot/-/blob/master/lib/smbios.c#L196Quoted 21 lines
Quoted 15 lines
lib/smbios.c +1
-2@@ -153,7 +153,7 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)static void smbios_set_eos (struct smbios_ctx *ctx,char *eos) { ctx->eos = eos; - ctx->next_ptr = eos; + ctx->next_ptr = eos +1 ; ctx->last_str =NULL ; } --Quoted 2 lines
2.30.2
Regards,
Simon