]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
acpi: use constants as strncpy limit
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 2 Feb 2021 22:52:53 +0000 (17:52 -0500)
committerMichael S. Tsirkin <mst@redhat.com>
Fri, 5 Feb 2021 13:52:59 +0000 (08:52 -0500)
gcc is not smart enough to figure out length was validated before use as
strncpy limit, resulting in this warning:

inlined from ‘virt_set_oem_table_id’ at ../../hw/arm/virt.c:2197:5:
/usr/include/aarch64-linux-gnu/bits/string_fortified.h:106:10: error:
‘__builtin_strncpy’ specified bound depends on the length of the
source argument [-Werror=stringop-overflow=]

Simplify things by using a constant limit instead.

Fixes: 97fc5d507fca ("acpi: Permit OEM ID and OEM table ID fields to be changed")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/arm/virt.c
hw/i386/microvm.c
hw/i386/pc.c

index 0c65fe38a0fd428737318a7c3a504a8fef54498e..371147f3ae9c2ea62a58aa5cca63e2734d1c3e7f 100644 (file)
@@ -2173,7 +2173,7 @@ static void virt_set_oem_id(Object *obj, const char *value, Error **errp)
         return;
     }
 
-    strncpy(vms->oem_id, value, len + 1);
+    strncpy(vms->oem_id, value, 6);
 }
 
 static char *virt_get_oem_table_id(Object *obj, Error **errp)
@@ -2194,7 +2194,7 @@ static void virt_set_oem_table_id(Object *obj, const char *value,
                    "User specified oem-table-id value is bigger than 8 bytes in size");
         return;
     }
-    strncpy(vms->oem_table_id, value, len + 1);
+    strncpy(vms->oem_table_id, value, 8);
 }
 
 
index 1dc2956e7230a2c3fb5bd8cc6dcb9979cbfb5d11..4e0cf4c522c9743751eafe9fae288232a34503b6 100644 (file)
@@ -668,7 +668,7 @@ static void microvm_machine_set_oem_id(Object *obj, const char *value,
         return;
     }
 
-    strncpy(mms->oem_id, value, len + 1);
+    strncpy(mms->oem_id, value, 6);
 }
 
 static char *microvm_machine_get_oem_table_id(Object *obj, Error **errp)
@@ -690,7 +690,7 @@ static void microvm_machine_set_oem_table_id(Object *obj, const char *value,
           "8 bytes in size");
         return;
     }
-    strncpy(mms->oem_table_id, value, len + 1);
+    strncpy(mms->oem_table_id, value, 8);
 }
 
 static void microvm_machine_initfn(Object *obj)
index 437977c49eb7542624d8e7d3b7d6c41e016e81ad..8aa85dec54ed27ce7d0a09496096825e176a802a 100644 (file)
@@ -1630,7 +1630,7 @@ static void pc_machine_set_oem_id(Object *obj, const char *value, Error **errp)
         return;
     }
 
-    strncpy(pcms->oem_id, value, len + 1);
+    strncpy(pcms->oem_id, value, 6);
 }
 
 static char *pc_machine_get_oem_table_id(Object *obj, Error **errp)
@@ -1652,7 +1652,7 @@ static void pc_machine_set_oem_table_id(Object *obj, const char *value,
           "8 bytes in size");
         return;
     }
-    strncpy(pcms->oem_table_id, value, len + 1);
+    strncpy(pcms->oem_table_id, value, 8);
 }
 
 static void pc_machine_initfn(Object *obj)