From patchwork Tue Apr 6 09:04:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 1462664 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=evT+J7Cr; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FF1nT5ghKz9sWX for ; Tue, 6 Apr 2021 19:05:01 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0022A8167E; Tue, 6 Apr 2021 11:04:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="evT+J7Cr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B8D35817B8; Tue, 6 Apr 2021 11:04:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 72BCE805B4 for ; Tue, 6 Apr 2021 11:04:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matthias.bgg@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 1D06F61396; Tue, 6 Apr 2021 09:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617699888; bh=jwo6EVNaFVSUNsXdSL9vBjnAvKR84plqw/pWBfdaQQU=; h=From:To:Cc:Subject:Date:From; b=evT+J7CrSpjsphzn/sISPedqI9q2N6jzFKavYpefx/+o9H0beoInkUXXsrf3O5Y/m vfNMH/g6JGaRWwl0N0j2walXGgV0Jc7lSPNmJTalk/EqBdaHPEoHFM+BU4AiSmXdwq 1SZchivwf2rjO3bP1Wf35GVlZp+QqlbCrIvpYMdVRtZ4EJo7iQTl+LAmiCHyoF3jTX hw7j7BDtBKxqQzzX6DiOwNEMeaxQdm4WJPXtZpvaZdqRoj6uwYcbQ+2FbeSwIyzdE5 4dI9nbMgFRoIxy9GWoM260Yk6NwqxxanD9HN/gcBzwi6LYAHTEUx/iSZadDffhL3sR pK+k+Bu2k1L4A== From: matthias.bgg@kernel.org To: sjg@chromium.org Cc: xypron.glpk@gmx.de, bmeng.cn@gmail.com, u-boot@lists.denx.de, Matthias Brugger , Christian Gmeiner Subject: [PATCH v2] smbios: Fix table when no string is present Date: Tue, 6 Apr 2021 11:04:35 +0200 Message-Id: <20210406090435.19357-1-matthias.bgg@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean From: Matthias Brugger When no string is present in a table, next_ptr points to the same location as eos. When calculating the string table length, we would only reserve one \0. By spec a SMBIOS table has to end with two \0\0 when no strings a present. Signed-off-by: Matthias Brugger Reviewed-by: Heinrich Schuchardt --- Changes in v2: - check in smbios_string_table_len if no string present and return value accordingly lib/smbios.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/smbios.c b/lib/smbios.c index 9eb226ec9f..fd57d8694f 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -191,6 +191,10 @@ int smbios_update_version(const char *version) */ static int smbios_string_table_len(const struct smbios_ctx *ctx) { + /* In case no string is defined we have to return two \0 */ + if (ctx->next_ptr == ctx->eos) + return 2; + /* Allow for the final \0 after all strings */ return (ctx->next_ptr + 1) - ctx->eos; }