From: Gerd Hoffmann Date: Mon, 20 Jan 2014 13:32:54 +0000 (+0100) Subject: smbios: catch zero-length strings X-Git-Tag: rel-1.7.5-rc1~76 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=344496fae4bee9243be7f9719a60b01189c12f00;p=seabios.git 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. Cc: armbru@redhat.com Signed-off-by: Gerd Hoffmann --- diff --git a/src/fw/smbios.c b/src/fw/smbios.c index affb9be..55c662a 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 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 { \