qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: seabios@seabios.org
Cc: armbru@redhat.com, qemu-devel@nongnu.org,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH] smbios: catch zero-length strings
Date: Tue, 21 Jan 2014 13:24:02 +0100	[thread overview]
Message-ID: <1390307042-28940-1-git-send-email-kraxel@redhat.com> (raw)

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 | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/fw/smbios.c b/src/fw/smbios.c
index affb9be..d549329 100644
--- a/src/fw/smbios.c
+++ b/src/fw/smbios.c
@@ -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 {                                                        \
-- 
1.8.3.1

             reply	other threads:[~2014-01-21 12:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21 12:24 Gerd Hoffmann [this message]
2014-01-21 13:26 ` [Qemu-devel] [SeaBIOS] [PATCH] smbios: catch zero-length strings Markus Armbruster
2014-01-22  7:58   ` Gerd Hoffmann
2014-01-21 19:52 ` Kevin O'Connor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390307042-28940-1-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).