e7a346
From 4d1636273b5333ed88ffd051c365490c73a380da Mon Sep 17 00:00:00 2001
e7a346
From: Pranith Kumar K <pkarampu@redhat.com>
e7a346
Date: Tue, 26 Jun 2018 15:58:02 +0530
e7a346
Subject: [PATCH 301/305] storage/posix: Fix posix_symlinks_match()
e7a346
e7a346
	Upstream patch: https://review.gluster.org/20399
e7a346
e7a346
1) snprintf into linkname_expected should happen with PATH_MAX
e7a346
2) comparison should happen with linkname_actual with complete
e7a346
   string linkname_expected
e7a346
e7a346
BUG: 1558989
e7a346
Change-Id: Ic3b3c362dc6c69c046b9a13e031989be47ecff14
e7a346
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/142486
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 tests/bugs/replicate/bug-1477169-entry-selfheal-rename.t | 15 ++++++++++-----
e7a346
 xlators/storage/posix/src/posix.c                        | 16 +++++++++++++---
e7a346
 2 files changed, 23 insertions(+), 8 deletions(-)
e7a346
e7a346
diff --git a/tests/bugs/replicate/bug-1477169-entry-selfheal-rename.t b/tests/bugs/replicate/bug-1477169-entry-selfheal-rename.t
e7a346
index 465800b..bb858a8 100644
e7a346
--- a/tests/bugs/replicate/bug-1477169-entry-selfheal-rename.t
e7a346
+++ b/tests/bugs/replicate/bug-1477169-entry-selfheal-rename.t
e7a346
@@ -13,10 +13,10 @@ EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 0
e7a346
 EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 1
e7a346
 EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status $V0 2
e7a346
 
e7a346
-TEST mkdir -p $M0/d1/dir $M0/d2
e7a346
+TEST mkdir -p $M0/d1/dir012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 $M0/d2
e7a346
 gfid_d1=$(gf_get_gfid_xattr $B0/${V0}0/d1)
e7a346
 gfid_d2=$(gf_get_gfid_xattr $B0/${V0}0/d2)
e7a346
-gfid_dir=$(gf_get_gfid_xattr $B0/${V0}0/d1/dir)
e7a346
+gfid_dir=$(gf_get_gfid_xattr $B0/${V0}0/d1/dir012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789)
e7a346
 
e7a346
 gfid_str_d1=$(gf_gfid_xattr_to_str $gfid_d1)
e7a346
 gfid_str_d2=$(gf_gfid_xattr_to_str $gfid_d2)
e7a346
@@ -24,7 +24,7 @@ gfid_str_d3=$(gf_gfid_xattr_to_str $gfid_dir)
e7a346
 
e7a346
 # Kill 3rd brick and rename the dir from mount.
e7a346
 TEST kill_brick $V0 $H0 $B0/${V0}2
e7a346
-TEST mv $M0/d1/dir $M0/d2
e7a346
+TEST mv $M0/d1/dir012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 $M0/d2
e7a346
 
e7a346
 # Bring it back and trigger heal.
e7a346
 TEST $CLI volume start $V0 force
e7a346
@@ -38,10 +38,15 @@ EXPECT_WITHIN $CHILD_UP_TIMEOUT "1" afr_child_up_status_in_shd $V0 2
e7a346
 TEST $CLI volume heal $V0
e7a346
 EXPECT_WITHIN $HEAL_TIMEOUT "^0$" get_pending_heal_count $V0
e7a346
 
e7a346
-# Check that .glusterfs symlink for dir exists and points to d2/dir
e7a346
+# Check that .glusterfs symlink for dir exists and points to d2/dir012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
e7a346
 TEST linkname=$(readlink $B0/${V0}2/.glusterfs/${gfid_str_d3:0:2}/${gfid_str_d3:2:2}/$gfid_str_d3)
e7a346
-EXPECT "dir" basename $linkname
e7a346
+EXPECT "dir012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" basename $linkname
e7a346
 TEST parent_dir_gfid_str=$(echo $linkname|cut -d / -f5)
e7a346
 EXPECT $gfid_str_d2 echo $parent_dir_gfid_str
e7a346
 
e7a346
+TEST rmdir $M0/d2/dir012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
e7a346
+
e7a346
+TEST ! stat $B0/${V0}0/.glusterfs/${gfid_str_d3:0:2}/${gfid_str_d3:2:2}/$gfid_str_d3
e7a346
+TEST ! stat $B0/${V0}1/.glusterfs/${gfid_str_d3:0:2}/${gfid_str_d3:2:2}/$gfid_str_d3
e7a346
+TEST ! stat $B0/${V0}2/.glusterfs/${gfid_str_d3:0:2}/${gfid_str_d3:2:2}/$gfid_str_d3
e7a346
 cleanup;
e7a346
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
e7a346
index 6aa64f9..af54882 100644
e7a346
--- a/xlators/storage/posix/src/posix.c
e7a346
+++ b/xlators/storage/posix/src/posix.c
e7a346
@@ -125,17 +125,27 @@ posix_symlinks_match (xlator_t *this, loc_t *loc, uuid_t gfid)
e7a346
         handle_size = POSIX_GFID_HANDLE_SIZE(priv->base_path_length);
e7a346
         dir_handle = alloca0 (handle_size);
e7a346
 
e7a346
-        snprintf (linkname_expected, handle_size, "../../%02x/%02x/%s/%s",
e7a346
+        snprintf (linkname_expected, PATH_MAX, "../../%02x/%02x/%s/%s",
e7a346
                   loc->pargfid[0], loc->pargfid[1], uuid_utoa (loc->pargfid),
e7a346
                   loc->name);
e7a346
 
e7a346
         MAKE_HANDLE_GFID_PATH (dir_handle, this, gfid, NULL);
e7a346
         len = sys_readlink (dir_handle, linkname_actual, PATH_MAX);
e7a346
-        if (len < 0)
e7a346
+        if (len < 0 || len == PATH_MAX) {
e7a346
+                if (len == PATH_MAX) {
e7a346
+                        errno = EINVAL;
e7a346
+                }
e7a346
+
e7a346
+                if (errno != ENOENT) {
e7a346
+                        gf_msg (this->name, GF_LOG_ERROR, errno,
e7a346
+                                P_MSG_LSTAT_FAILED, "readlink[%s] failed",
e7a346
+                                dir_handle);
e7a346
+                }
e7a346
                 goto out;
e7a346
+        }
e7a346
         linkname_actual[len] = '\0';
e7a346
 
e7a346
-        if (!strncmp (linkname_actual, linkname_expected, handle_size))
e7a346
+        if (!strcmp (linkname_actual, linkname_expected))
e7a346
                 ret = _gf_true;
e7a346
 
e7a346
 out:
e7a346
-- 
e7a346
1.8.3.1
e7a346