Skip to contentSkip to conversation

libnfs4acl: Check file mode before getxattr call

PATCH In review Kenneth D'souza 2 participants 3 messages Aug 11, 2022 – Sep 13, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libnfs4acl: Check file mode before getxattr call

Currently we are checking file mode after getxattr call.
Due to this the return value would be 0, which would change the getxattr return value. As xattr_size will be 0, nfs4_getfacl will fail with error EINVAL.
This patch fixes this issue by moving the file mode check before getxattr call.

---
 libnfs4acl/nfs4_getacl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
libnfs4acl/nfs4_getacl.c +7 -7
index 7821da3..aace5cd 100644
@@ -39,6 +39,13 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path,
 		return NULL;
 	}
 
+	ret = stat(path, &st);
+	if (ret == -1)
+		goto err;
+
+	if (S_ISDIR(st.st_mode))
+		iflags = NFS4_ACL_ISDIR;
+
 	/* find necessary buffer size */
 	ret = getxattr(path, xattr_name, NULL, 0);
 	if (ret == -1)
@@ -53,13 +60,6 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path,
 	if (ret == -1)
 		goto err_free;
 
-	ret = stat(path, &st);
-	if (ret == -1)
-		goto err_free;
-
-	if (S_ISDIR(st.st_mode))
-		iflags = NFS4_ACL_ISDIR;
-
 	acl = acl_nfs41_xattr_load(buf, ret, iflags, type);
 
 	free(buf);
Signature · 1 line
2.31.1
#1 lore raw

ping

Quoted 47 lines · Kenneth D'souza

Currently we are checking file mode after getxattr call.
Due to this the return value would be 0, which would change the getxattr return value. As xattr_size will be 0, nfs4_getfacl will fail with error EINVAL.
This patch fixes this issue by moving the file mode check before getxattr call.

---
 libnfs4acl/nfs4_getacl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
libnfs4acl/nfs4_getacl.c +7 -8
index 7821da3..aace5cd 100644
@@ -39,6 +39,13 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path,
                return NULL;
        }
 
+       ret = stat(path, &st);
+       if (ret == -1)
+               goto err;
+
+       if (S_ISDIR(st.st_mode))
+               iflags = NFS4_ACL_ISDIR;
+
        /* find necessary buffer size */
        ret = getxattr(path, xattr_name, NULL, 0);
        if (ret == -1)
@@ -53,13 +60,6 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path,
        if (ret == -1)
                goto err_free;
 
-       ret = stat(path, &st);
-       if (ret == -1)
-               goto err_free;
-
-       if (S_ISDIR(st.st_mode))
-               iflags = NFS4_ACL_ISDIR;
-
        acl = acl_nfs41_xattr_load(buf, ret, iflags, type);
 
        free(buf);
--

2.31.1

#2 lore raw
Quoted 1 line · Kenneth Dsouza

ping

Sorry about that... Thanks for the ping!

Quoted 10 lines · Kenneth D'souza
Quoted 8 lines

Currently we are checking file mode after getxattr call.
Due to this the return value would be 0, which would change the getxattr return value. As xattr_size will be 0, nfs4_getfacl will fail with error EINVAL.
This patch fixes this issue by moving the file mode check before getxattr call.

Committed... (tag: nfs4-acl-tools-0.4.1-rc2)

steved.

Quoted 40 lines
Quoted 39 lines
---
  libnfs4acl/nfs4_getacl.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
libnfs4acl/nfs4_getacl.c +7 -8
index 7821da3..aace5cd 100644
@@ -39,6 +39,13 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path,
                 return NULL;
         }
 
+       ret = stat(path, &st);
+       if (ret == -1)
+               goto err;
+
+       if (S_ISDIR(st.st_mode))
+               iflags = NFS4_ACL_ISDIR;
+
         /* find necessary buffer size */
         ret = getxattr(path, xattr_name, NULL, 0);
         if (ret == -1)
@@ -53,13 +60,6 @@ static struct nfs4_acl *nfs4_getacl_byname(const char *path,
         if (ret == -1)
                 goto err_free;
 
-       ret = stat(path, &st);
-       if (ret == -1)
-               goto err_free;
-
-       if (S_ISDIR(st.st_mode))
-               iflags = NFS4_ACL_ISDIR;
-
         acl = acl_nfs41_xattr_load(buf, ret, iflags, type);
 
         free(buf);
--

2.31.1