[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] remap translator: remap prefixes instead of complete file na
From: |
Samuel Thibault |
Subject: |
Re: [PATCH] remap translator: remap prefixes instead of complete file names |
Date: |
Sun, 15 Dec 2019 20:10:45 +0100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Joan Lledó via Bug reports for the GNU Hurd, le dim. 15 déc. 2019 19:57:43
+0100, a ecrit:
> diff --git a/trans/remap.c b/trans/remap.c
> index 5afbaa02..e3d5fa0a 100644
> --- a/trans/remap.c
> +++ b/trans/remap.c
> @@ -65,19 +65,23 @@ trivfs_S_dir_lookup (struct trivfs_protid *diruser,
> mach_msg_type_name_t *retry_port_type)
> {
> struct remap *remap;
> + char dest[NAME_MAX] = { };
Rather use string_t, which is the actual type of retry_name.
> - if (!strcmp (remap->from, filename))
> + if (!strncmp (remap->from, filename, strlen (remap->from)))
You need to avoid the case when filename happens to begin like
remap->from, e.g. remap has a /foo -> /bar translation, and the entry to
be translated is /foo2, we don't want to remap in that case. The matched
part thus have to be followed by either \0 or '/', otherwise it's not a
match.
> + snprintf (dest, NAME_MAX, "%s%s", remap->to,
Rather use sizeof() here.
> + filename + strlen (remap->from));
Compute strlen(remap->from) only once.
> - filename = remap->to;
> +
> + strncpy (filename, dest, NAME_MAX);
No, you shouldn't modify filename. And you can just set filename = dest.
Samuel