Blob Blame History Raw
From ba6951c82c8af1c9fd4669d8561517bd7850eeee Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Wed, 22 Jan 2014 09:32:53 -0500
Subject: [PATCH 2/6] smbios: catch zero-length strings

Message-id: <1390383173-24339-2-git-send-email-kraxel@redhat.com>
Patchwork-id: 56881
O-Subject: [RHEL-7 seabios PATCH 1/1] smbios: catch zero-length strings
Bugzilla: 1052837
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>

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>
(cherry picked from commit 344496fae4bee9243be7f9719a60b01189c12f00)
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>

Conflicts:
	src/smbios.c
---
 src/smbios.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
 src/smbios.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/smbios.c b/src/smbios.c
index 23713a2..4e6df14 100644
--- a/src/smbios.c
+++ b/src/smbios.c
@@ -61,13 +61,17 @@ smbios_entry_point_init(u16 max_structure_size,
         size = qemu_cfg_smbios_load_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)                             \
@@ -75,7 +79,7 @@ smbios_entry_point_init(u16 max_structure_size,
         size = qemu_cfg_smbios_load_field(type,                         \
                                  offsetof(struct smbios_type_##type,    \
                                           field), end);                 \
-        if (size > 0) {                                                 \
+        if (size > 1) {                                                 \
             end += size;                                                \
             p->field = ++str_index;                                     \
         } else {                                                        \
-- 
1.8.3.1