提交 5cdcb75d 编写于 作者: L Laine Stump

network: log error for unknown virNetworkUpdate command codes

Every level of the code for virNetworkUpdate was assuming that some
other level was checking for validity of the "command" arg, but none
actually were. The result was that an invalid command code would do
nothing, but also report success.

Since the command code isn't used until the very lowest level backend
functions, that's where I put the check. I made a separate one-line
function to log the error. The compiler would have combined the
identical strings used by multiple calls if I'd just called
virReportError directly in each location, but sending them all to the
same string in the source guards against inadvertant divergence (which
would lead to extra work for translators.)
上级 f59e25e0
...@@ -2260,6 +2260,12 @@ virNetworkDefUpdateNoSupport(virNetworkDefPtr def, const char *section) ...@@ -2260,6 +2260,12 @@ virNetworkDefUpdateNoSupport(virNetworkDefPtr def, const char *section)
_("can't update '%s' section of network '%s'"), _("can't update '%s' section of network '%s'"),
section, def->name); section, def->name);
} }
static void
virNetworkDefUpdateUnknownCommand(unsigned int command)
{
virReportError(VIR_ERR_NO_SUPPORT,
_("unrecognized network update command code %d"), command);
}
static int static int
virNetworkDefUpdateCheckElementName(virNetworkDefPtr def, virNetworkDefUpdateCheckElementName(virNetworkDefPtr def,
...@@ -2484,6 +2490,9 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def, ...@@ -2484,6 +2490,9 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
sizeof(*ipdef->hosts) * (ipdef->nhosts - ii - 1)); sizeof(*ipdef->hosts) * (ipdef->nhosts - ii - 1));
ipdef->nhosts--; ipdef->nhosts--;
ignore_value(VIR_REALLOC_N(ipdef->hosts, ipdef->nhosts)); ignore_value(VIR_REALLOC_N(ipdef->hosts, ipdef->nhosts));
} else {
virNetworkDefUpdateUnknownCommand(command);
goto cleanup;
} }
ret = 0; ret = 0;
...@@ -2581,6 +2590,9 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr def, ...@@ -2581,6 +2590,9 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr def,
sizeof(*ipdef->ranges) * (ipdef->nranges - ii - 1)); sizeof(*ipdef->ranges) * (ipdef->nranges - ii - 1));
ipdef->nranges--; ipdef->nranges--;
ignore_value(VIR_REALLOC_N(ipdef->ranges, ipdef->nranges)); ignore_value(VIR_REALLOC_N(ipdef->ranges, ipdef->nranges));
} else {
virNetworkDefUpdateUnknownCommand(command);
goto cleanup;
} }
ret = 0; ret = 0;
...@@ -2701,6 +2713,9 @@ virNetworkDefUpdatePortGroup(virNetworkDefPtr def, ...@@ -2701,6 +2713,9 @@ virNetworkDefUpdatePortGroup(virNetworkDefPtr def,
sizeof(*def->portGroups) * (def->nPortGroups - ii - 1)); sizeof(*def->portGroups) * (def->nPortGroups - ii - 1));
def->nPortGroups--; def->nPortGroups--;
ignore_value(VIR_REALLOC_N(def->portGroups, def->nPortGroups)); ignore_value(VIR_REALLOC_N(def->portGroups, def->nPortGroups));
} else {
virNetworkDefUpdateUnknownCommand(command);
goto cleanup;
} }
ret = 0; ret = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册