diff mbox series

[hurd,commited,4/4] hurd: Fix getxattr/listxattr returning ERANGE

Message ID 20240610200930.616306-5-samuel.thibault@ens-lyon.org
State New
Headers show
Series hurd xattr fixes | expand

Commit Message

Samuel Thibault June 10, 2024, 8:09 p.m. UTC
The manpage says that when the passed size is zero, they should set the
expected size and return 0. ERANGE shall be returned only when the non-zero
passed size is not large enough.
---
 hurd/xattr.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/hurd/xattr.c b/hurd/xattr.c
index 1a84c90db8..2d83edf2fe 100644
--- a/hurd/xattr.c
+++ b/hurd/xattr.c
@@ -50,7 +50,15 @@  _hurd_xattr_get (io_t port, const char *name, void *value, size_t *size)
       else if (value)
 	{
 	  if (*size < sizeof st.st_author)
-	    return ERANGE;
+	    {
+	      if (*size > 0)
+		return ERANGE;
+	      else
+		{
+		  *size = sizeof st.st_author;
+		  return 0;
+		}
+	    }
 	  memcpy (value, &st.st_author, sizeof st.st_author);
 	}
       *size = sizeof st.st_author;
@@ -73,12 +81,21 @@  _hurd_xattr_get (io_t port, const char *name, void *value, size_t *size)
       err = __file_get_translator (port, &buf, &bufsz);
       if (err)
 	return err;
-      if (value != NULL && *size < bufsz)
+
+      if (*size < bufsz)
 	{
 	  if (buf != value)
 	    __munmap (buf, bufsz);
-	  return ERANGE;
+
+	  if (*size > 0)
+	    return ERANGE;
+	  else
+	    {
+	      *size = bufsz;
+	      return 0;
+	    }
 	}
+
       if (buf != value && bufsz > 0)
 	{
 	  if (value != NULL)
@@ -201,7 +218,7 @@  _hurd_xattr_list (io_t port, void *buffer, size_t *size)
   if (st.st_mode & S_IPTRANS)
     add ("gnu.translator");
 
-  if (buffer != NULL && total > *size)
+  if (*size > 0 && total > *size)
     return ERANGE;
   *size = total;
   return 0;