From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5aNN-0002XZ-SC for qemu-devel@nongnu.org; Tue, 21 Jan 2014 07:24:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5aNH-0005Fh-Rl for qemu-devel@nongnu.org; Tue, 21 Jan 2014 07:24:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26261) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5aNH-0005FS-85 for qemu-devel@nongnu.org; Tue, 21 Jan 2014 07:24:11 -0500 From: Gerd Hoffmann Date: Tue, 21 Jan 2014 13:24:02 +0100 Message-Id: <1390307042-28940-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH] smbios: catch zero-length strings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: seabios@seabios.org Cc: armbru@redhat.com, qemu-devel@nongnu.org, 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. Fix this by handling zero-length strings like non-present strings. Cc: armbru@redhat.com Signed-off-by: Gerd Hoffmann --- 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