From 6e8e837864d4e24c2fdb4d90e8eb262ded78c3a8 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 28 Feb 2016 01:52:11 +0100 Subject: Fix mustbedir mechanism for symlinks * libdiskfs/dir-lookup.c (diskfs_S_dir_lookup): When following a symlink, if mustbedir is true, always append a slash to the symlink target, not only when the target is absolute. Reset mustbedir to 0 before continuing the lookup loop. * libnetfs/dir-lookup.c (netfs_S_dir_lookup): When following a symlink, if mustbedir is true, append a slash to the symlink target. Reset mustbedir to 0 before continuing the lookup loop. * libtreefs/dir-lookup.c (_treefs_s_dir_lookup): Likewise. --- libdiskfs/dir-lookup.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'libdiskfs/dir-lookup.c') diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c index 8b986e49..c50970d2 100644 --- a/libdiskfs/dir-lookup.c +++ b/libdiskfs/dir-lookup.c @@ -421,24 +421,25 @@ diskfs_S_dir_lookup (struct protid *dircred, memcpy (pathbuf + np->dn_stat.st_size + 1, nextname, nextnamelen - 1); } - pathbuf[nextnamelen + np->dn_stat.st_size] = '\0'; + if (mustbedir) + { + pathbuf[nextnamelen + np->dn_stat.st_size] = '/'; + pathbuf[nextnamelen + np->dn_stat.st_size + 1] = '\0'; + } + else + pathbuf[nextnamelen + np->dn_stat.st_size] = '\0'; if (pathbuf[0] == '/') { /* Punt to the caller. */ *retry = FS_RETRY_MAGICAL; *returned_port = MACH_PORT_NULL; - memcpy (retryname, pathbuf, - nextnamelen + np->dn_stat.st_size + 1); - if (mustbedir) - { - retryname[nextnamelen + np->dn_stat.st_size] = '/'; - retryname[nextnamelen + np->dn_stat.st_size + 1] = '\0'; - } + strcpy (retryname, pathbuf); goto out; } path = pathbuf; + mustbedir = 0; } if (lastcomp) -- cgit v1.2.3