Recent changes uncovered FORWARD_NULL and NEGATIVE_RETURNS problems with the processing of the 'nActiveIfaces' and 'nInactiveIfaces' and their associated allocated arrays in 'vshInterfaceListCollect' due to the possibility of returning -1 in a call and using the return value as a for loop index end condition. --- tools/virsh-interface.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 9fdd36e..5ee16a3 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -199,6 +199,7 @@ vshInterfaceListCollect(vshControl *ctl, int nActiveIfaces = 0; int nInactiveIfaces = 0; int nAllIfaces = 0; + int rc; /* try the list with flags support (0.10.2 and later) */ if ((ret = virConnectListAllInterfaces(ctl->conn, @@ -222,16 +223,17 @@ fallback: vshResetLibvirtError(); if (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE) { - nActiveIfaces = virConnectNumOfInterfaces(ctl->conn); - if (nActiveIfaces < 0) { + rc = virConnectNumOfInterfaces(ctl->conn); + if (rc < 0) { vshError(ctl, "%s", _("Failed to list active interfaces")); goto cleanup; } - if (nActiveIfaces) { + if (rc) { + nActiveIfaces = rc; activeNames = vshMalloc(ctl, sizeof(char *) * nActiveIfaces); - if ((nActiveIfaces = virConnectListInterfaces(ctl->conn, activeNames, - nActiveIfaces)) < 0) { + if ((rc = virConnectListInterfaces(ctl->conn, activeNames, + nActiveIfaces)) < 0) { vshError(ctl, "%s", _("Failed to list active interfaces")); goto cleanup; } @@ -239,17 +241,17 @@ fallback: } if (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE) { - nInactiveIfaces = virConnectNumOfDefinedInterfaces(ctl->conn); - if (nInactiveIfaces < 0) { + rc = virConnectNumOfDefinedInterfaces(ctl->conn); + if (rc < 0) { vshError(ctl, "%s", _("Failed to list inactive interfaces")); goto cleanup; } - if (nInactiveIfaces) { + if (rc) { + nInactiveIfaces = rc; inactiveNames = vshMalloc(ctl, sizeof(char *) * nInactiveIfaces); - if ((nInactiveIfaces = - virConnectListDefinedInterfaces(ctl->conn, inactiveNames, - nInactiveIfaces)) < 0) { + if ((rc = virConnectListDefinedInterfaces(ctl->conn, inactiveNames, + nInactiveIfaces)) < 0) { vshError(ctl, "%s", _("Failed to list inactive interfaces")); goto cleanup; } -- 1.8.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list