]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix fsconfig value unescaping
authorKarel Zak <kzak@redhat.com>
Fri, 1 Dec 2023 10:10:50 +0000 (11:10 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 1 Dec 2023 10:10:50 +0000 (11:10 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/hook_mount.c

index 7143450fb7da2f985e42725a6918d3ca4e72e708..961cc8745d0f5f25d2dea6b0a017f1987b0ee8d3 100644 (file)
@@ -150,22 +150,29 @@ static inline int fsconfig_set_value(
                        const char *name, const char *value)
 {
        int rc;
-       char *p = NULL;
+       char *s = NULL;
 
+       /* "\," is a way to use comma in values, let's remove \ escape */
        if (value && strstr(value, "\\,")) {
-               p = strdup(value);
-               if (!p)
-                       return -EINVAL;
+               char *x, *p;
 
-               strrem(p, '\\');
-               value = p;
+               s = strdup(value);
+               if (!s)
+                       return -EINVAL;
+               for (x = p = s; *x; p++, x++) {
+                       if (*x == '\\' && *(x + 1) == ',')
+                               x++;
+                       *p = *x;
+               }
+               *p = '\0';
+               value = s;
        }
 
        DBG(HOOK, ul_debugobj(hs, "  fsconfig(name=\"%s\" value=\"%s\")", name,
                                value ? : ""));
        if (value) {
                rc = fsconfig(fd, FSCONFIG_SET_STRING, name, value, 0);
-               free(p);
+               free(s);
        } else
                rc = fsconfig(fd, FSCONFIG_SET_FLAG, name, NULL, 0);