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

Pavel Emelyanov xemul at parallels.com
Fri Jul 17 06:16:06 PDT 2015


On 07/17/2015 01:49 PM, Andrey Vagin wrote:
> mountinfo contains mangled paths. space, tab and back slash were
> replaced with usual octal escape, so we need to replace these charecter
> back.
> 
> 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 fc2e371..0fa2afe 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.
> + */
> +void cure_path(char *path) { int i, len, off = 0;

static

> +
> +	if (strchr(path, '\\') == NULL) /* fast path */
> +		return;

What's so fast in it? It scans through the whole string anyway.

> +
> +	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;
> @@ -1034,6 +1068,8 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
>  			goto err;
>  	}
>  
> +	cure_path(new->source);
> +
>  	/*
>  	 * The kernel reports "subtypes" sometimes and the valid
>  	 * type-vs-subtype delimiter is the dot symbol. We disregard
> 



More information about the CRIU mailing list