all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com, Kaiyang Wu <wukaiyang2003@gmail.com>
Cc: Kaiyang Wu <wukaiyang@loongfans.cn>
Subject: Re: [PATCH qemu-server] query-machine-capabilities: check vendor string length for strncmp
Date: Mon, 13 Jul 2026 16:15:28 +0200	[thread overview]
Message-ID: <1783951945.bjj3it71oe.astroid@yuna.none> (raw)
In-Reply-To: <20260603055031.106241-1-wukaiyang@loongfans.cn>

On June 3, 2026 7:50 am, Kaiyang Wu wrote:
> Fix build error on unknown vendors ('fallback'):
> 
> 	error: ‘strncmp’ of strings of length 7 and 12 and bound of 12 evaluates to nonzero [-Werror=string-compare]
> 
> Signed-off-by: Kaiyang Wu <wukaiyang@loongfans.cn>
> ---
>  src/query-machine-capabilities/query-machine-capabilities.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> 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", strerror(errno));
>      }
>  
> -    if (strncmp(vendor, "AuthenticAMD", 12) == 0) {
> +    if (strncmp(vendor, "AuthenticAMD", strnlen(vendor, 12)) == 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);
>  
> @@ -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) == 0) {
> +    } else if (strncmp(vendor, "GenuineIntel", strnlen(vendor, 12)) == 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) == 0) {
>              ret = fprintf(file,
> -- 
> 2.52.0
> 
> 
> 
> 
> 




      parent reply	other threads:[~2026-07-13 14:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  5:50 [PATCH qemu-server] query-machine-capabilities: check vendor string length for strncmp Kaiyang Wu
2026-06-16  9:01 ` Kaiyang Wu
2026-07-13 14:15 ` Fabian Grünbichler [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1783951945.bjj3it71oe.astroid@yuna.none \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=wukaiyang2003@gmail.com \
    --cc=wukaiyang@loongfans.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal