]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroupv2: fix parsing multiple values in single file
authorPavel Hrdina <phrdina@redhat.com>
Mon, 19 Aug 2019 14:01:50 +0000 (16:01 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 20 Aug 2019 15:37:37 +0000 (17:37 +0200)
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 <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/util/vircgroupv2.c

index e36c36685b6d0332d6310fe633fcfb4fbfd2f1de..59ef2e63978a951748176240b06cdfd14ed74cbb 100644 (file)
@@ -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;