From nobody Mon Nov 10 07:52:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1555005188; cv=none; d=zoho.com; s=zohoarc; b=ISi1yoyGXo8zi8h3zIcTtvtufEJ9gkgTfREg4o4etDhkLRqRXpXsaOmUoMS1XkjgVL1l1fQeC5P2dg2Bpwpur63ZwjrxvCVx3MjOUCicI/q6nJjTSeMoWTS3Z1FUnP3v6OTB4KWbC1CW07dovzgXOuWHmlrAOEc27Gjrl/jT1Xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555005188; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=Bp5poo3PHihZOlMKSwxzCWo0yMLOd345hhzSJfjvQTw=; b=DtPbzIks464F6tqFUPweh/brFjGd5Rych3DN+JO3nvysuE+UP7iuj5+1pufrBgJMbVqJIiV+40+oPyhdHKRi4mnHTQHfHbiI75VUrN6Pvhr4IHuNo21JggFalBeo35Gg0quwcs3egASOnuODv2JhJevU/TJK51m0PWht+AtZTOw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=null header.from= header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555005188680686.0801746150391; Thu, 11 Apr 2019 10:53:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:52890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEdsf-0001jX-TT for importer@patchew.org; Thu, 11 Apr 2019 13:52:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hEdrh-0001QQ-VS for qemu-devel@nongnu.org; Thu, 11 Apr 2019 13:51:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hEdrg-0005ke-1U for qemu-devel@nongnu.org; Thu, 11 Apr 2019 13:51:57 -0400 Received: from inet-orm.provo.novell.com ([137.65.248.124]:48681 helo=mail.novell.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hEdre-0005ZR-6X for qemu-devel@nongnu.org; Thu, 11 Apr 2019 13:51:54 -0400 Received: from brogers1.provo.novell.com (brogers1.dnsdhcp.provo.novell.com [137.65.133.7]) by mail.novell.com with ESMTP (NOT encrypted); Thu, 11 Apr 2019 11:51:43 -0600 From: Bruce Rogers To: qemu-devel@nongnu.org Date: Thu, 11 Apr 2019 11:51:38 -0600 Message-Id: <20190411175138.12838-1-brogers@suse.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.248.124 Subject: [Qemu-devel] [PATCH] hw/smbios: handle both file formats regardless of machine type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bruce Rogers , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It's easy enough to handle either per-spec or legacy smbios structures in the smbios file input without regard to the machine type used, by simply applying the basic smbios formatting rules. then depending on what is detected. terminal numm bytes are added or removed for machine type specific processing. Signed-off-by: Bruce Rogers --- hw/smbios/smbios.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 47be9071fa..d4b95ebc84 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -960,6 +960,7 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) struct smbios_structure_header *header; int size; struct smbios_table *table; /* legacy mode only */ + uint8_t *dbl_nulls, *orig_end; =20 qemu_opts_validate(opts, qemu_smbios_file_opts, &err); if (err) { @@ -974,11 +975,21 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) } =20 /* - * NOTE: standard double '\0' terminator expected, per smbios spec. - * (except in legacy mode, where the second '\0' is implicit and - * will be inserted by the BIOS). + * NOTE: standard double '\0' terminator expected, per smbios spec, + * unless the data is formatted for legacy mode, which is used by + * pc-i440fx-2.0 and earlier machine types. Legacy mode structures + * without strings have no '\0' terminators, and those with strings + * also don't have an additional '\0' terminator at the end of the + * final string '\0' terminator. The BIOS will add the '\0' termin= ators + * to comply with the smbios spec. + * For greater compatibility, regardless of the machine type used, + * either format is accepted. */ - smbios_tables =3D g_realloc(smbios_tables, smbios_tables_len + siz= e); + smbios_tables =3D g_realloc(smbios_tables, smbios_tables_len + siz= e + 2); + orig_end =3D smbios_tables + smbios_tables_len + size; + /* add extra null bytes to end in case of legacy file data */ + *orig_end =3D '\0'; + *(orig_end + 1) =3D '\0'; header =3D (struct smbios_structure_header *)(smbios_tables + smbios_tables_len); =20 @@ -993,6 +1004,19 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) header->type); return; } + for (dbl_nulls =3D smbios_tables + smbios_tables_len + header->len= gth; + dbl_nulls + 2 <=3D orig_end; dbl_nulls++) { + if (*dbl_nulls =3D=3D '\0' && *(dbl_nulls + 1) =3D=3D '\0') { + break; + } + } + if (dbl_nulls + 2 < orig_end) { + error_setg(errp, "SMBIOS file data malformed"); + return; + } + /* increase size by how many extra nulls were actually needed */ + size +=3D dbl_nulls + 2 - orig_end; + smbios_tables =3D g_realloc(smbios_tables, smbios_tables_len + siz= e); set_bit(header->type, have_binfile_bitmap); =20 if (header->type =3D=3D 4) { @@ -1013,6 +1037,17 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) * delete the one we don't need from smbios_set_defaults(), * once we know which machine version has been requested. */ + if (dbl_nulls + 2 =3D=3D orig_end) { + /* chop off nulls to get legacy format */ + if (header->length + 2 =3D=3D size) { + size -=3D 2; + } else { + size -=3D 1; + } + } else { + /* undo conversion from legacy format to per-spec format */ + size -=3D dbl_nulls + 2 - orig_end; + } if (!smbios_entries) { smbios_entries_len =3D sizeof(uint16_t); smbios_entries =3D g_malloc0(smbios_entries_len); --=20 2.21.0