Skip to contentSkip to conversation

smbios: catch zero-length strings

PATCH In review Gerd Hoffmann 3 participants 4 messages Jan 21, 2014 – Jan 22, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smbios: catch zero-length strings

qemu may pass us zero-length strings for smbios fields, when starting qemu this way ...

qemu -smbios type=1,version=,serial=test

... for example.

Today we don't specifically handle them and simply append them to the string list. Therefore we get two string-terminating zeros in a row. Result is that we by accident create a end-of-entry marker in the middle of the entry.

Fix this by handling zero-length strings like non-present strings.

---
 src/fw/smbios.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
src/fw/smbios.c +7 -3
index affb9be..d549329 100644
@@ -133,20 +133,24 @@ get_external(int type, char **p, unsigned *nr_structs,
     do {                                                                \
         size = get_field(type, offsetof(struct smbios_type_##type,      \
                                         field), end);                   \
-        if (size > 0) {                                                 \
+        if (size == 1) {                                                \
+            /* zero-length string, skip to avoid bogous end marker */   \
+            p->field = 0;                                               \
+        } else if (size > 1) {                                          \
             end += size;                                                \
+            p->field = ++str_index;                                     \
         } else {                                                        \
             memcpy(end, def, sizeof(def));                              \
             end += sizeof(def);                                         \
+            p->field = ++str_index;                                     \
         }                                                               \
-        p->field = ++str_index;                                         \
     } while (0)
 
 #define load_str_field_or_skip(type, field)                             \
     do {                                                                \
         size = get_field(type, offsetof(struct smbios_type_##type,      \
                                         field), end);                   \
-        if (size > 0) {                                                 \
+        if (size > 1) {                                                 \
             end += size;                                                \
             p->field = ++str_index;                                     \
         } else {                                                        \
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Gerd Hoffmann

qemu may pass us zero-length strings for smbios fields, when starting qemu this way ...

qemu -smbios type=1,version=,serial=test

... for example.

Today we don't specifically handle them and simply append them to the string list. Therefore we get two string-terminating zeros in a row. Result is that we by accident create a end-of-entry marker in the middle of the entry.

And dmidecode screaming bloody murder :) More detail than you probably want to know at https://bugzilla.redhat.com/show_bug.cgi?id=1052837

Quoted 4 lines

Fix this by handling zero-length strings like non-present strings.

Spelling correction inline.

Quoted 9 lines
---
 src/fw/smbios.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
src/fw/smbios.c +0 -0
index affb9be..d549329 100644

src/fw/smbios.c get_external(int type, char **p, unsigned *nr_structs, · line 137

Quoted 6 lines
src/fw/smbios.c +2 -1
@@ -133,20 +133,24 @@ get_external(int type, char **p, unsigned *nr_structs,
     do {                                                                \
         size = get_field(type, offsetof(struct smbios_type_##type,      \
                                         field), end);                   \
-        if (size > 0) {                                                 \
+        if (size == 1) {                                                \
+            /* zero-length string, skip to avoid bogous end marker */   \

s/bogous/bogus/

Quoted 21 lines
src/fw/smbios.c +5 -2
+            p->field = 0;                                               \
+        } else if (size > 1) {                                          \
             end += size;                                                \
+            p->field = ++str_index;                                     \
         } else {                                                        \
             memcpy(end, def, sizeof(def));                              \
             end += sizeof(def);                                         \
+            p->field = ++str_index;                                     \
         }                                                               \
-        p->field = ++str_index;                                         \
     } while (0)
 
 #define load_str_field_or_skip(type, field)                             \
     do {                                                                \
         size = get_field(type, offsetof(struct smbios_type_##type,      \
                                         field), end);                   \
-        if (size > 0) {                                                 \
+        if (size > 1) {                                                 \
             end += size;                                                \
             p->field = ++str_index;                                     \
         } else {                                                        \
#2 lore raw
Quoted 4 lines · Markus Armbruster
Quoted 1 line

+ /* zero-length string, skip to avoid bogous end marker

*/ \

s/bogous/bogus/

Applied spell fix and pushed.

cheers,
Gerd

#3 lore raw
In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann

qemu may pass us zero-length strings for smbios fields, when starting qemu this way ...

qemu -smbios type=1,version=,serial=test

Quoted 8 lines

... for example.

Today we don't specifically handle them and simply append them to the string list. Therefore we get two string-terminating zeros in a row. Result is that we by accident create a end-of-entry marker in the middle of the entry.

Fix this by handling zero-length strings like non-present strings.

Looks okay to me.

I wish we could get all of the smbios stuff moved to qemu.

-Kevin