]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Properly terminate string list in virshDomainInterfaceSourceModeCompleter()
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 11 Mar 2022 08:13:56 +0000 (09:13 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 15 Mar 2022 12:36:43 +0000 (13:36 +0100)
A completer must return a NULL terminated list of strings, which
means that when dealing with enums, it has to allocate one
pointer more than the value of VIR_XXX_LAST. But this is not
honoured in virshDomainInterfaceSourceModeCompleter() leading to
out of bounds read.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
tools/virsh-completer-domain.c

index 250dd8b21aaa98c79377bdd690fad5553b6f0d97..9cc27b84cba832820c503671e15a3491bf157323 100644 (file)
@@ -500,7 +500,7 @@ virshDomainInterfaceSourceModeCompleter(vshControl *ctl G_GNUC_UNUSED,
 
     virCheckFlags(0, NULL);
 
-    ret = g_new0(char *, VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST);
+    ret = g_new0(char *, VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST + 1);
 
     for (i = 0; i < VIRSH_DOMAIN_INTERFACE_SOURCE_MODE_LAST; i++)
         ret[i] = g_strdup(virshDomainInterfaceSourceModeTypeToString(i));