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 <[email protected]>
---
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