[libvirt] [PATCH libvirt-python 1/2] setPyVirTypedParameter: Copy full field name
Martin Kletzander
mkletzan at redhat.com
Tue Mar 18 09:14:00 UTC 2014
On Tue, Mar 18, 2014 at 09:26:08AM +0100, Michal Privoznik wrote:
> In the setPyVirTypedParameter we try to produce virTypedParameter
> array from a pyhthon dictionary. However, when copying field name into
s/pyhthon/python/
> 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 at redhat.com>
ACK.
Martin
> ---
> libvirt-override.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/libvirt-override.c b/libvirt-override.c
> index 83369fc..3765a43 100644
> --- a/libvirt-override.c
> +++ b/libvirt-override.c
> @@ -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);
>
> --
> 1.9.0
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140318/68b38a1e/attachment-0001.sig>
More information about the libvir-list
mailing list