[CRIU] [PATCH 2/4] mount: decode paths from mountinfo (v2)

Andrey Vagin avagin at openvz.org
Fri Jul 17 07:40:23 PDT 2015


mountinfo contains mangled paths. space, tab and back slash were
replaced with usual octal escape, so we need to replace these charecter
back.

v2: declare cure_path as static
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 proc_parse.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/proc_parse.c b/proc_parse.c
index 1267f26..8a03fea 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -988,6 +988,37 @@ static int parse_mnt_opt(char *str, struct mount_info *mi, int *off)
 	return 0;
 }
 
+/*
+ * mountinfo contains mangled paths. space, tab and back slash were replaced
+ * with usual octal escape. This function replaces these symbols back.
+ */
+static void cure_path(char *path) { int i, len, off = 0;
+
+	if (strchr(path, '\\') == NULL) /* fast path */
+		return;
+
+	len = strlen(path);
+	for (i = 0; i < len; i++) {
+		if (!strncmp(path + i, "\\040", 4)) {
+			path[i - off] = ' ';
+			goto replace;
+		} else if (!strncmp(path + i, "\\011", 4)) {
+			path[i - off] = '\t';
+			goto replace;
+		} else if (!strncmp(path + i, "\\134", 4)) {
+			path[i - off] = '\\';
+			goto replace;
+		}
+		if (off)
+			path[i - off] = path[i];
+		continue;
+replace:
+		off += 3;
+		i += 3;
+	}
+	path[len - off] = 0;
+}
+
 static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
 {
 	unsigned int kmaj, kmin;
@@ -1006,6 +1037,9 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
 	if (ret != 7)
 		goto err;
 
+	cure_path(new->mountpoint);
+	cure_path(new->root);
+
 	new->mountpoint = xrealloc(new->mountpoint, strlen(new->mountpoint) + 1);
 	if (!new->mountpoint)
 		goto err;
@@ -1033,6 +1067,8 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
 	} else if (ret != 3)
 		goto err;
 
+	cure_path(new->source);
+
 	/*
 	 * The kernel reports "subtypes" sometimes and the valid
 	 * type-vs-subtype delimiter is the dot symbol. We disregard
-- 
2.1.0



More information about the CRIU mailing list