]> xenbits.xensource.com Git - seabios.git/commitdiff
smbios: catch zero-length strings
authorGerd Hoffmann <kraxel@redhat.com>
Mon, 20 Jan 2014 13:32:54 +0000 (14:32 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 22 Jan 2014 07:55:08 +0000 (08:55 +0100)
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.

Cc: armbru@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
src/fw/smbios.c

index affb9be440c78cda3eb3a70889c7a23354c0a843..55c662ae828194a92f88e1328a37df205b7edd95 100644 (file)
@@ -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 bogus 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 {                                                        \