]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgset: Fix parsing of name/values with an '=' in the value
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 30 Mar 2021 18:54:06 +0000 (18:54 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 2 Apr 2021 19:02:47 +0000 (13:02 -0600)
Fix parsing of name/value pairs that contain an '='
character in the value string.  For example, the io.max
setting utilizes the '=' character:
cgset -r io.max="8:16 wbps=1024" foo

Fixes: https://github.com/libcgroup/libcgroup/issues/33
Reported-by: Santiago Ruano Rincón <santiago.ruano-rincon@imt-atlantique.fr>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgset.c

index 9d4abbca94b7b4ecaefb0a65631e8ec61d25e81b..4e8c1e7e1aa4bf131cef35251c43d4d85c575bc3 100644 (file)
@@ -100,8 +100,13 @@ static int parse_r_flag(const char * const program_name,
        strncpy(name_value->name, buf, FILENAME_MAX);
        name_value->name[FILENAME_MAX-1] = '\0';
 
-       buf = strtok(NULL, "=");
-       if (buf == NULL) {
+       buf = strchr(name_value_str, '=');
+       /* we don't need to check the return value of strchr because we
+        * know there's already an '=' character in the string.
+        */
+       buf++;
+
+       if (strlen(buf) == 0) {
                fprintf(stderr, "%s: "
                        "wrong parameter of option -r: %s\n",
                        program_name, optarg);