From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 0B6931FF0E1 for ; Mon, 13 Jul 2026 16:15:38 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6C5E921352; Mon, 13 Jul 2026 16:15:37 +0200 (CEST) Date: Mon, 13 Jul 2026 16:15:28 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= Subject: Re: [PATCH qemu-server] query-machine-capabilities: check vendor string length for strncmp To: pve-devel@lists.proxmox.com, Kaiyang Wu References: <20260603055031.106241-1-wukaiyang@loongfans.cn> In-Reply-To: <20260603055031.106241-1-wukaiyang@loongfans.cn> MIME-Version: 1.0 User-Agent: astroid/0.17.0 (https://github.com/astroidmail/astroid) Message-Id: <1783951945.bjj3it71oe.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783952116469 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.400 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: G4P7YCWL4VBEESCR6LJDLMQ5AKIZ2OO2 X-Message-ID-Hash: G4P7YCWL4VBEESCR6LJDLMQ5AKIZ2OO2 X-MailFrom: f.gruenbichler@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Kaiyang Wu X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On June 3, 2026 7:50 am, Kaiyang Wu wrote: > Fix build error on unknown vendors ('fallback'): >=20 > error: =E2=80=98strncmp=E2=80=99 of strings of length 7 and 12 and bound= of 12 evaluates to nonzero [-Werror=3Dstring-compare] >=20 > Signed-off-by: Kaiyang Wu > --- > src/query-machine-capabilities/query-machine-capabilities.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/src/query-machine-capabilities/query-machine-capabilities.c = b/src/query-machine-capabilities/query-machine-capabilities.c > index abb47acd..25d06db7 100644 > --- a/src/query-machine-capabilities/query-machine-capabilities.c > +++ b/src/query-machine-capabilities/query-machine-capabilities.c > @@ -204,7 +204,7 @@ int main() { > eprintf("Error writing to file '" OUTPUT_PATH "': %s\n", strerro= r(errno)); > } > =20 > - if (strncmp(vendor, "AuthenticAMD", 12) =3D=3D 0) { > + if (strncmp(vendor, "AuthenticAMD", strnlen(vendor, 12)) =3D=3D 0) { this is wrong - if the vendor is "Authentic" the code would now think it's AMD.. the same would be true if vendor is "AuthenticAMDsomething", because it would only look at the first 12 bytes (granted, that is a pre-existing issue ;)). instead, we'd first need to check for the length, and if it is 12, do the existing checks, if not, either add checks for other vendors, or reject/abort.. > cpu_caps_amd_sev_t caps_sev; > query_cpu_capabilities_sev(&caps_sev); > =20 > @@ -222,7 +222,7 @@ int main() { > caps_sev.sev_es_support ? "true" : "false", > caps_sev.sev_snp_support ? "true" : "false" > ); > - } else if (strncmp(vendor, "GenuineIntel", 12) =3D=3D 0) { > + } else if (strncmp(vendor, "GenuineIntel", strnlen(vendor, 12)) =3D= =3D 0) { same applies here, but with `Genuine` (or any other substring prefix of `GenuineIntel`).. > cpu_caps_intel_tdx_t caps_tdx; > if (query_cpu_capabilities_tdx(&caps_tdx) =3D=3D 0) { > ret =3D fprintf(file, > --=20 > 2.52.0 >=20 >=20 >=20 >=20 >=20