When attempting to strip the root path, we should first canonicalise the root pathname. Signed-off-by: Trond Myklebust <trond.myklebust@xxxxxxxxxxxxxxx> --- support/misc/nfsd_path.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index 2f41a793c534..9b38dd96007f 100644 --- a/support/misc/nfsd_path.c +++ b/support/misc/nfsd_path.c @@ -1,6 +1,7 @@ #include <errno.h> #include <sys/types.h> #include <sys/stat.h> +#include <limits.h> #include <stdlib.h> #include <unistd.h> @@ -62,13 +63,21 @@ nfsd_path_nfsd_rootdir(void) char * nfsd_path_strip_root(char *pathname) { + char buffer[PATH_MAX]; const char *dir = nfsd_path_nfsd_rootdir(); char *ret; - ret = strstr(pathname, dir); - if (!ret || ret != pathname) - return pathname; - return pathname + strlen(dir); + if (!dir) + goto out; + if (realpath(dir, buffer)) { + ret = strstr(pathname, buffer); + if (ret == pathname) + return pathname + strlen(dir); + } else + xlog(D_GENERAL, "%s: failed to resolve path %s: %m", + __func__, dir); +out: + return pathname; } char * -- 2.21.0