src: Use virStrcpyStatic() to avoid truncation

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>
This commit is contained in:
Andrea Bolognani 2018-07-17 10:21:50 +02:00
parent f508a65a21
commit c9d5f2d989
2 changed files with 2 additions and 5 deletions

View 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);

View 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);