a3470f
From 2489f91d395740b42f21322744ab64427e94a683 Mon Sep 17 00:00:00 2001
a3470f
From: Jiffin Tony Thottan <jthottan@redhat.com>
a3470f
Date: Tue, 31 Jul 2018 14:52:51 +0530
a3470f
Subject: [PATCH 346/351] gfapi : Handle the path == "" glfs_resolve_at
a3470f
a3470f
Currently there is no check for path = "" in glfs_resolve_at.
a3470f
So if application sends an empty path, then the function resolves
a3470f
into the parent inode which is incorrect. Plus modified possible
a3470f
of "path" with "origpath" in the same function.
a3470f
a3470f
Upstream reference
a3470f
>Change-Id: Ie5ff9ce4b771607b7dbb3fe00704fe670421792a
a3470f
>fixes: bz#1610236
a3470f
>Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
a3470f
>link : https://review.gluster.org/#/c/glusterfs/+/20594/
a3470f
a3470f
Change-Id: Ie5ff9ce4b771607b7dbb3fe00704fe670421792a
a3470f
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/146938
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 api/src/glfs-resolve.c | 17 ++++++++++-------
a3470f
 1 file changed, 10 insertions(+), 7 deletions(-)
a3470f
a3470f
diff --git a/api/src/glfs-resolve.c b/api/src/glfs-resolve.c
a3470f
index 76835cb..95fe67a 100644
a3470f
--- a/api/src/glfs-resolve.c
a3470f
+++ b/api/src/glfs-resolve.c
a3470f
@@ -472,14 +472,13 @@ priv_glfs_resolve_at (struct glfs *fs, xlator_t *subvol, inode_t *at,
a3470f
 	DECLARE_OLD_THIS;
a3470f
 	__GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs);
a3470f
 
a3470f
-	path = gf_strdup (origpath);
a3470f
-	if (!path) {
a3470f
-		errno = ENOMEM;
a3470f
-		return -1;
a3470f
-	}
a3470f
+        if (origpath[0] == '\0') {
a3470f
+                errno = EINVAL;
a3470f
+                goto invalid_fs;
a3470f
+        }
a3470f
 
a3470f
 	parent = NULL;
a3470f
-	if (at && path[0] != '/') {
a3470f
+	if (at && origpath[0] != '/') {
a3470f
 		/* A relative resolution of a path which starts with '/'
a3470f
 		   is equal to an absolute path resolution.
a3470f
 		*/
a3470f
@@ -487,10 +486,14 @@ priv_glfs_resolve_at (struct glfs *fs, xlator_t *subvol, inode_t *at,
a3470f
 	} else {
a3470f
 		inode = inode_ref (subvol->itable->root);
a3470f
 
a3470f
-		if (strcmp (path, "/") == 0)
a3470f
+		if (strcmp (origpath, "/") == 0)
a3470f
                         glfs_resolve_root (fs, subvol, inode, &ciatt);
a3470f
 	}
a3470f
 
a3470f
+        path = gf_strdup (origpath);
a3470f
+	if (!path)
a3470f
+		goto invalid_fs;
a3470f
+
a3470f
 	for (component = strtok_r (path, "/", &saveptr);
a3470f
 	     component; component = next_component) {
a3470f
 
a3470f
-- 
a3470f
1.8.3.1
a3470f