From nobody Thu Sep 19 00:56:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1721311842282688.1451403380272; Thu, 18 Jul 2024 07:10:42 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2C85C9BC; Thu, 18 Jul 2024 10:10:41 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 60D4DCAD; Thu, 18 Jul 2024 10:08:32 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 29E9EA66; Thu, 18 Jul 2024 10:08:26 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id DC033A09 for ; Thu, 18 Jul 2024 10:08:18 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-mdjYjksONaanPdo7ax2ZLQ-1; Thu, 18 Jul 2024 10:08:17 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7790F1955D54 for ; Thu, 18 Jul 2024 14:08:16 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A0A931955E80 for ; Thu, 18 Jul 2024 14:08:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: ** X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721311698; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pa6TtVNwRQmG6gk3evTm7dcUxLt3Tz1GKDFqAbbaxXM=; b=RbOGVLquRT5rrmvvjO5c2+sIpSvL1qqxf9SVaI8Mn+dSyZZONAtYxwLFBLh9QIHWmQw4oL 2rXUEA0HPa+NqfM+dyXZ63UQZ64X+rareGiGWETnHQoPQpqD5uC01WMXLUBH0ByR5O0VRN cctfiPa8mm5Th/CbtivM4mPuBNFwE3I= X-MC-Unique: mdjYjksONaanPdo7ax2ZLQ-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 5/5] virsysinfo: Calculate OEM string index better Date: Thu, 18 Jul 2024 16:08:07 +0200 Message-ID: <434af362b6e511dca9d4a9ccb7aca12c1a0c0b9c.1721311651.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: MOGOFQZ7LHNN7BUJXJFYC7RHPUU2MXHQ X-Message-ID-Hash: MOGOFQZ7LHNN7BUJXJFYC7RHPUU2MXHQ X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1721311844462116600 Content-Type: text/plain; charset="utf-8"; x-default="true" As can be seen in earlier commits, there can be two OEM strings with the same index. But since our parser (virSysinfoParseOEMStrings()) doesn't expect that, it increments index in each run and thus skips over these strings. Fortunately, we have the right index at hand - we're just skipping over it in a loop. Just reconstruct the index back inside the loop. Signed-off-by: Michal Privoznik --- src/util/virsysinfo.c | 19 ++++++++++++------- .../aarch64-hpe-apollosysinfo.expect | 4 +--- tests/sysinfotest.c | 6 +++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 1fd8261dc1..8823af0469 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -895,13 +895,13 @@ virSysinfoParseX86Chassis(const char *base, =20 =20 static int -virSysinfoDMIDecodeOEMString(size_t i, +virSysinfoDMIDecodeOEMString(unsigned int idx, char **str) { g_autofree char *err =3D NULL; g_autoptr(virCommand) cmd =3D virCommandNewArgList(DMIDECODE, "--dump", "--oem-string", NULL); - virCommandAddArgFormat(cmd, "%zu", i); + virCommandAddArgFormat(cmd, "%u", idx); virCommandSetOutputBuffer(cmd, str); virCommandSetErrorBuffer(cmd, &err); =20 @@ -937,7 +937,6 @@ virSysinfoParseOEMStrings(const char *base, virSysinfoOEMStringsDef **stringsRet) { virSysinfoOEMStringsDef *strings =3D NULL; - size_t i =3D 1; int ret =3D -1; const char *cur; =20 @@ -947,6 +946,8 @@ virSysinfoParseOEMStrings(const char *base, strings =3D g_new0(virSysinfoOEMStringsDef, 1); =20 while ((cur =3D strstr(cur, "String "))) { + char *collon =3D NULL; + unsigned int idx =3D 0; char *eol; =20 cur +=3D 7; @@ -957,8 +958,13 @@ virSysinfoParseOEMStrings(const char *base, goto cleanup; } =20 - while (g_ascii_isdigit(*cur)) - cur++; + if (virStrToLong_ui(cur, &collon, 10, &idx) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Malformed output of dmidecode")); + goto cleanup; + } + + cur =3D collon; =20 if (*cur !=3D ':') { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -981,7 +987,7 @@ virSysinfoParseOEMStrings(const char *base, if (memchr(cur, '.', eol - cur)) { char *str; =20 - if (virSysinfoDMIDecodeOEMString(i, &str) < 0) + if (virSysinfoDMIDecodeOEMString(idx, &str) < 0) goto cleanup; =20 strings->values[strings->nvalues - 1] =3D g_steal_pointer(&str= ); @@ -989,7 +995,6 @@ virSysinfoParseOEMStrings(const char *base, strings->values[strings->nvalues - 1] =3D g_strndup(cur, eol -= cur); } =20 - i++; cur =3D eol; } =20 diff --git a/tests/sysinfodata/aarch64-hpe-apollosysinfo.expect b/tests/sys= infodata/aarch64-hpe-apollosysinfo.expect index 331454834d..2b886f74fd 100644 --- a/tests/sysinfodata/aarch64-hpe-apollosysinfo.expect +++ b/tests/sysinfodata/aarch64-hpe-apollosysinfo.expect @@ -82,9 +82,7 @@ Default string ThunderX2 System - Ha ha ha try parsing\n - String 3: this correctly - String 4:then + Some valid OEM string Comanche diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index d8bd1f38ba..b666847379 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -63,7 +63,11 @@ testDMIDecodeDryRun(const char *const*args G_GNUC_UNUSED, return; } =20 - if (STREQ(args[3], "3")) { + if (STREQ(args[3], "2")) { + *output =3D g_strdup("Some valid OEM string\n"); + *error =3D g_strdup_printf("No OEM string number %s", args[3]); + return; + } else if (STREQ(args[3], "3")) { *output =3D g_strdup("Ha ha ha try parsing\\n\n" " String 3: this correctly\n" " String 4:then\n"); --=20 2.44.2