1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

completer: Doesn't alloc enough space for null terminated array of strings

Functions virshSecretEventNameCompleter, virshPoolEventNameCompleter,
virshNodedevEventNameCompleter allocates only enough space
for array of N strings.

However these are null terminated strings, so program needs to
alloc space for array of N + 1 strings.

How to replicate error: valgrind virsh, use completer for
'nodedev-event --event' or 'pool-event --event' or
'secret-event --event'.

Signed-off-by: Simon Kobyda <skobyda@redhat.com>
This commit is contained in:
Simon Kobyda 2018-07-12 16:00:08 +02:00 committed by Michal Privoznik
parent 073d5041c7
commit 9413442224

View File

@ -709,7 +709,7 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
virCheckFlags(0, NULL);
if (VIR_ALLOC_N(ret, VIR_SECRET_EVENT_ID_LAST) < 0)
if (VIR_ALLOC_N(ret, VIR_SECRET_EVENT_ID_LAST + 1) < 0)
goto error;
for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) {
@ -761,7 +761,7 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
virCheckFlags(0, NULL);
if (VIR_ALLOC_N(ret, VIR_STORAGE_POOL_EVENT_ID_LAST) < 0)
if (VIR_ALLOC_N(ret, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0)
goto error;
for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) {
@ -787,7 +787,7 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
virCheckFlags(0, NULL);
if (VIR_ALLOC_N(ret, VIR_NODE_DEVICE_EVENT_ID_LAST) < 0)
if (VIR_ALLOC_N(ret, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0)
goto error;
for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) {