From 0894e1d3af83228fb02310e61c1dafea2dc56ef9 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Tue, 26 Jun 2018 15:58:02 +0530 Subject: storage/posix: Fix posix_symlinks_match() 1) snprintf into linkname_expected should happen with PATH_MAX 2) comparison should happen with linkname_actual with complete string linkname_expected fixes bz#1595524 Change-Id: Ic3b3c362dc6c69c046b9a13e031989be47ecff14 Signed-off-by: Pranith Kumar K (cherry picked from commit 3099d3e6ba81d3e1abf37385b13aabf5837b9c5e) --- xlators/storage/posix/src/posix-entry-ops.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'xlators/storage') diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c index 519b6f3f040..b4bbafae91a 100644 --- a/xlators/storage/posix/src/posix-entry-ops.c +++ b/xlators/storage/posix/src/posix-entry-ops.c @@ -104,17 +104,27 @@ posix_symlinks_match (xlator_t *this, loc_t *loc, uuid_t gfid) handle_size = POSIX_GFID_HANDLE_SIZE(priv->base_path_length); dir_handle = alloca0 (handle_size); - snprintf (linkname_expected, handle_size, "../../%02x/%02x/%s/%s", + snprintf (linkname_expected, PATH_MAX, "../../%02x/%02x/%s/%s", loc->pargfid[0], loc->pargfid[1], uuid_utoa (loc->pargfid), loc->name); MAKE_HANDLE_GFID_PATH (dir_handle, this, gfid, NULL); len = sys_readlink (dir_handle, linkname_actual, PATH_MAX); - if (len < 0) + if (len < 0 || len == PATH_MAX) { + if (len == PATH_MAX) { + errno = EINVAL; + } + + if (errno != ENOENT) { + gf_msg (this->name, GF_LOG_ERROR, errno, + P_MSG_LSTAT_FAILED, "readlink[%s] failed", + dir_handle); + } goto out; + } linkname_actual[len] = '\0'; - if (!strncmp (linkname_actual, linkname_expected, handle_size)) + if (!strcmp (linkname_actual, linkname_expected)) ret = _gf_true; out: -- cgit