1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-30 23:41:52 +03:00

setPyVirTypedParameter: Copy full field name

In the setPyVirTypedParameter we try to produce virTypedParameter
array from a python dictionary. However, when copying field name into
item in returned array, we use strncpy() as the field name is fixed
length array. To determine its size we use sizeof() but mistakenly
dereference it resulting in sizeof(char) which equals to 1 byte.
Moreover, there's no need for using sizeof() when we have a global
macro to tell us the length of the field name:
VIR_TYPED_PARAM_FIELD_LENGTH.

And since array is allocated using VIR_ALLOC() we are sure the memory
is initially filled with zeros. Hence, there's no need to terminate
string we've just copied into field name with '\0' character. It's
there for sure too as we copy up to field length - 1.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik
2014-03-18 09:12:24 +01:00
parent f738e4162e
commit 412c93a7b9

View File

@ -197,8 +197,7 @@ setPyVirTypedParameter(PyObject *info,
goto cleanup;
}
strncpy(temp->field, keystr, sizeof(*temp->field) - 1);
temp->field[sizeof(*temp->field) - 1] = '\0';
strncpy(temp->field, keystr, VIR_TYPED_PARAM_FIELD_LENGTH - 1);
temp->type = params[i].type;
VIR_FREE(keystr);