From: Pavel Hrdina Date: Mon, 19 Aug 2019 14:01:50 +0000 (+0200) Subject: vircgroupv2: fix parsing multiple values in single file X-Git-Tag: v5.7.0-rc1~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c854e0bd33c7a5afb04a36465bf04f861b2efef5;p=thirdparty%2Flibvirt.git vircgroupv2: fix parsing multiple values in single file Our virStrToLong* helpers converts string to integers where it wraps strtol standard function. After the conversion happens and there are some remaining invalid characters our helpers will fail if the second argument is NULL. We need to pass pointer to string in cases where there are multiple values in a single file. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1741825 Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index e36c36685b..59ef2e6397 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -673,7 +673,7 @@ virCgroupV2GetBlkioWeight(virCgroupPtr group, tmp = value; } - if (virStrToLong_ui(tmp, NULL, 10, weight) < 0) { + if (virStrToLong_ui(tmp, &tmp, 10, weight) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), tmp); @@ -869,7 +869,7 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, if (!str) { *weight = 0; - } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) { + } else if (virStrToLong_ui(str, &str, 10, weight) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -939,7 +939,7 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *riops = 0; - } else if (virStrToLong_ui(tmp, NULL, 10, riops) < 0) { + } else if (virStrToLong_ui(tmp, &tmp, 10, riops) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1010,7 +1010,7 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *wiops = 0; - } else if (virStrToLong_ui(tmp, NULL, 10, wiops) < 0) { + } else if (virStrToLong_ui(tmp, &tmp, 10, wiops) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1081,7 +1081,7 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *rbps = 0; - } else if (virStrToLong_ull(tmp, NULL, 10, rbps) < 0) { + } else if (virStrToLong_ull(tmp, &tmp, 10, rbps) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1152,7 +1152,7 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group, if (STREQLEN(tmp, "max", 3)) { *wbps = 0; - } else if (virStrToLong_ull(tmp, NULL, 10, wbps) < 0) { + } else if (virStrToLong_ull(tmp, &tmp, 10, wbps) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); @@ -1535,7 +1535,7 @@ virCgroupV2GetCpuCfsPeriod(virCgroupPtr group, return -1; } - if (virStrToLong_ull(tmp, NULL, 10, cfs_period) < 0) { + if (virStrToLong_ull(tmp, &tmp, 10, cfs_period) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse value '%s' from cpu.max."), str); return -1; @@ -1585,7 +1585,7 @@ virCgroupV2GetCpuCfsQuota(virCgroupPtr group, if (STREQLEN(str, "max", 3)) *cfs_quota = ULLONG_MAX / 1000; - if (virStrToLong_ll(str, NULL, 10, cfs_quota) < 0) { + if (virStrToLong_ll(str, &str, 10, cfs_quota) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse value '%s' from cpu.max."), str); return -1;