mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 23:07:44 +00:00
util: fix bug found by Coverity
Commit 861d40565
added code (my personal change to "clean up" the
submitter's code, *not* the fault of the submitter) that dereferenced
virtVlan without first checking for NULL. This patch fixes that and,
as part of the fix, cleans up some unnecessary obtuseness.
This commit is contained in:
parent
0fc12bca08
commit
003118deb4
@ -81,9 +81,27 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
|
||||
goto out_of_memory;
|
||||
}
|
||||
|
||||
cmd = virCommandNew(OVSVSCTL);
|
||||
|
||||
virCommandAddArgList(cmd, "--timeout=5", "--", "--may-exist", "add-port",
|
||||
brname, ifname, NULL);
|
||||
|
||||
if (virtVlan && virtVlan->nTags > 0) {
|
||||
|
||||
/* Trunk port first */
|
||||
switch (virtVlan->nativeMode) {
|
||||
case VIR_NATIVE_VLAN_MODE_TAGGED:
|
||||
virCommandAddArg(cmd, "vlan_mode=native-tagged");
|
||||
virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
|
||||
break;
|
||||
case VIR_NATIVE_VLAN_MODE_UNTAGGED:
|
||||
virCommandAddArg(cmd, "vlan_mode=native-untagged");
|
||||
virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
|
||||
break;
|
||||
case VIR_NATIVE_VLAN_MODE_DEFAULT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (virtVlan->trunk) {
|
||||
virBufferAddLit(&buf, "trunk=");
|
||||
|
||||
@ -99,33 +117,15 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
|
||||
virBufferAddLit(&buf, ",");
|
||||
virBufferAsprintf(&buf, "%d", virtVlan->tag[i]);
|
||||
}
|
||||
|
||||
if (virBufferError(&buf))
|
||||
goto out_of_memory;
|
||||
virCommandAddArg(cmd, virBufferCurrentContent(&buf));
|
||||
} else if (virtVlan->nTags) {
|
||||
virBufferAsprintf(&buf, "tag=%d", virtVlan->tag[0]);
|
||||
virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]);
|
||||
}
|
||||
}
|
||||
|
||||
cmd = virCommandNew(OVSVSCTL);
|
||||
|
||||
virCommandAddArgList(cmd, "--timeout=5", "--", "--may-exist", "add-port",
|
||||
brname, ifname, NULL);
|
||||
|
||||
switch (virtVlan->nativeMode) {
|
||||
case VIR_NATIVE_VLAN_MODE_TAGGED:
|
||||
virCommandAddArg(cmd, "vlan_mode=native-tagged");
|
||||
virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
|
||||
break;
|
||||
case VIR_NATIVE_VLAN_MODE_UNTAGGED:
|
||||
virCommandAddArg(cmd, "vlan_mode=native-untagged");
|
||||
virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag);
|
||||
break;
|
||||
case VIR_NATIVE_VLAN_MODE_DEFAULT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (virBufferUse(&buf) != 0)
|
||||
virCommandAddArgList(cmd, virBufferCurrentContent(&buf), NULL);
|
||||
|
||||
if (ovsport->profileID[0] == '\0') {
|
||||
virCommandAddArgList(cmd,
|
||||
"--", "set", "Interface", ifname, attachedmac_ex_id,
|
||||
|
Loading…
Reference in New Issue
Block a user