diff mbox series

libnfs4acl: Check file mode before getxattr call

Message ID 20220811184645.467066-1-kdsouza@redhat.com (mailing list archive)
State New, archived
Headers show
Series libnfs4acl: Check file mode before getxattr call | expand

Commit Message

Kenneth Dsouza Aug. 11, 2022, 6:46 p.m. UTC
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.

Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
---
 libnfs4acl/nfs4_getacl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libnfs4acl/nfs4_getacl.c b/libnfs4acl/nfs4_getacl.c
index 7821da3..f9c5831 100644
--- a/libnfs4acl/nfs4_getacl.c
+++ b/libnfs4acl/nfs4_getacl.c
@@ -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_free;
+
+	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);