]> xenbits.xensource.com Git - libvirt.git/commitdiff
src: Use virStrcpyStatic() to avoid truncation
authorAndrea Bolognani <abologna@redhat.com>
Tue, 17 Jul 2018 08:21:50 +0000 (10:21 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 23 Jul 2018 12:27:13 +0000 (14:27 +0200)
The way virStrncpy() is called here will never result in
buffer overflow, but it won't prevent or detect truncation
either, despite what the error message might suggest. Use
virStrcpyStatic(), which does all of the above, instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
src/esx/esx_driver.c
src/hyperv/hyperv_driver.c

index 947b7c1a31be10b3857bf98972137181ee17efbb..edd21b9d285af204ac1a5e8f3a97371ff978351c 100644 (file)
@@ -1317,9 +1317,7 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
                 ++ptr;
             }
 
-            if (!virStrncpy(nodeinfo->model, dynamicProperty->val->string,
-                            sizeof(nodeinfo->model) - 1,
-                            sizeof(nodeinfo->model))) {
+            if (!virStrcpyStatic(nodeinfo->model, dynamicProperty->val->string)) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("CPU Model %s too long for destination"),
                                dynamicProperty->val->string);
index a85943668c200d83239f54c544cd962020f40dd8..6f74adf372921224c21749acc4cf87ee834adff8 100644 (file)
@@ -307,8 +307,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
     }
 
     /* Fill struct */
-    if (virStrncpy(info->model, processorList->data.common->Name,
-                   sizeof(info->model) - 1, sizeof(info->model)) == NULL) {
+    if (virStrcpyStatic(info->model, processorList->data.common->Name) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("CPU model %s too long for destination"),
                        processorList->data.common->Name);