virNetDevBandwidthParseRate: Reject negative values

https://bugzilla.redhat.com/show_bug.cgi?id=1022292

The following XML really does not make any sense:

<inbound average="-1" burst="-2" peak="-3" floor="-4"/>

There can't be a negative packet rate. Well, so far we haven't
assigned any meaning to it. So reject it unless users harm themselves,
because otherwise we turn the negative numbers into really big values.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-08-07 17:03:12 +02:00
parent 17cba9fb51
commit 2a5d3f227d

View File

@ -50,7 +50,7 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRatePtr rate)
floor = virXMLPropString(node, "floor"); floor = virXMLPropString(node, "floor");
if (average) { if (average) {
if (virStrToLong_ull(average, NULL, 10, &rate->average) < 0) { if (virStrToLong_ullp(average, NULL, 10, &rate->average) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not convert bandwidth average value '%s'"), _("could not convert bandwidth average value '%s'"),
average); average);
@ -68,21 +68,21 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRatePtr rate)
goto cleanup; goto cleanup;
} }
if (peak && virStrToLong_ull(peak, NULL, 10, &rate->peak) < 0) { if (peak && virStrToLong_ullp(peak, NULL, 10, &rate->peak) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not convert bandwidth peak value '%s'"), _("could not convert bandwidth peak value '%s'"),
peak); peak);
goto cleanup; goto cleanup;
} }
if (burst && virStrToLong_ull(burst, NULL, 10, &rate->burst) < 0) { if (burst && virStrToLong_ullp(burst, NULL, 10, &rate->burst) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not convert bandwidth burst value '%s'"), _("could not convert bandwidth burst value '%s'"),
burst); burst);
goto cleanup; goto cleanup;
} }
if (floor && virStrToLong_ull(floor, NULL, 10, &rate->floor) < 0) { if (floor && virStrToLong_ullp(floor, NULL, 10, &rate->floor) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not convert bandwidth floor value '%s'"), _("could not convert bandwidth floor value '%s'"),
floor); floor);