public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [hurd,commited 0/4] hurd xattr fixes
@ 2024-06-10 20:09 Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 1/4] hurd: Fix lsetxattr return value Samuel Thibault
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Samuel Thibault @ 2024-06-10 20:09 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

These fix a few corner cases of the xattr interface.

Samuel Thibault (4):
  hurd: Fix lsetxattr return value
  hurd: Fix getxattr("gnu.translator") returning ENODATA
  hurd: Fix setxattr return value on replacing
  hurd: Fix getxattr/listxattr returning ERANGE

 hurd/xattr.c                  | 43 +++++++++++++++++++++++++++--------
 sysdeps/mach/hurd/lsetxattr.c |  2 +-
 2 files changed, 35 insertions(+), 10 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [hurd,commited 1/4] hurd: Fix lsetxattr return value
  2024-06-10 20:09 [hurd,commited 0/4] hurd xattr fixes Samuel Thibault
@ 2024-06-10 20:09 ` Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 2/4] hurd: Fix getxattr("gnu.translator") returning ENODATA Samuel Thibault
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2024-06-10 20:09 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

The manpage says that lsetxattr returns 0 on success, like setxattr.
---
 sysdeps/mach/hurd/lsetxattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/mach/hurd/lsetxattr.c b/sysdeps/mach/hurd/lsetxattr.c
index 3f5d335a1a..49487f78fb 100644
--- a/sysdeps/mach/hurd/lsetxattr.c
+++ b/sysdeps/mach/hurd/lsetxattr.c
@@ -32,5 +32,5 @@ lsetxattr (const char *path, const char *name, const void *value, size_t size,
     return -1;
   err = _hurd_xattr_set (port, name, value, size, flags);
   __mach_port_deallocate (__mach_task_self (), port);
-  return err ? __hurd_fail (err) : size;
+  return __hurd_fail (err);
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [hurd,commited 2/4] hurd: Fix getxattr("gnu.translator") returning ENODATA
  2024-06-10 20:09 [hurd,commited 0/4] hurd xattr fixes Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 1/4] hurd: Fix lsetxattr return value Samuel Thibault
@ 2024-06-10 20:09 ` Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 3/4] hurd: Fix setxattr return value on replacing Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 4/4] hurd: Fix getxattr/listxattr returning ERANGE Samuel Thibault
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2024-06-10 20:09 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

When no translator is set, __file_get_translator would return EINVAL
which is a confusing value. Better check for a passive translation
before getting the value.
---
 hurd/xattr.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/hurd/xattr.c b/hurd/xattr.c
index 0715ad7b02..f613d47c83 100644
--- a/hurd/xattr.c
+++ b/hurd/xattr.c
@@ -61,7 +61,16 @@ _hurd_xattr_get (io_t port, const char *name, void *value, size_t *size)
     {
       char *buf = value;
       mach_msg_type_number_t bufsz = value ? *size : 0;
-      error_t err = __file_get_translator (port, &buf, &bufsz);
+      struct stat64 st;
+      error_t err;
+
+      err = __io_stat (port, &st);
+      if (err)
+	return err;
+      if ((st.st_mode & S_IPTRANS) == 0)
+	return ENODATA;
+
+      err = __file_get_translator (port, &buf, &bufsz);
       if (err)
 	return err;
       if (value != NULL && *size < bufsz)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [hurd,commited 3/4] hurd: Fix setxattr return value on replacing
  2024-06-10 20:09 [hurd,commited 0/4] hurd xattr fixes Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 1/4] hurd: Fix lsetxattr return value Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 2/4] hurd: Fix getxattr("gnu.translator") returning ENODATA Samuel Thibault
@ 2024-06-10 20:09 ` Samuel Thibault
  2024-06-10 20:09 ` [hurd,commited 4/4] hurd: Fix getxattr/listxattr returning ERANGE Samuel Thibault
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2024-06-10 20:09 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

When XATTR_REPLACE is set we shall succeed when the value already
exists, and fail with ENODATA otherwise, instead of the converse.
---
 hurd/xattr.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hurd/xattr.c b/hurd/xattr.c
index f613d47c83..1a84c90db8 100644
--- a/hurd/xattr.c
+++ b/hurd/xattr.c
@@ -158,10 +158,9 @@ _hurd_xattr_set (io_t port, const char *name, const void *value, size_t size,
 	  if (err)
 	    return err;
 	  if (bufsz > 0)
-	    {
-	      __munmap (buf, bufsz);
-	      return ENODATA;
-	    }
+	    __munmap (buf, bufsz);
+	  else
+	    return ENODATA;
 	}
       return __file_set_translator (port,
 				    FS_TRANS_SET | ((flags & XATTR_CREATE)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [hurd,commited 4/4] hurd: Fix getxattr/listxattr returning ERANGE
  2024-06-10 20:09 [hurd,commited 0/4] hurd xattr fixes Samuel Thibault
                   ` (2 preceding siblings ...)
  2024-06-10 20:09 ` [hurd,commited 3/4] hurd: Fix setxattr return value on replacing Samuel Thibault
@ 2024-06-10 20:09 ` Samuel Thibault
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2024-06-10 20:09 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

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 --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;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-10 20:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-10 20:09 [hurd,commited 0/4] hurd xattr fixes Samuel Thibault
2024-06-10 20:09 ` [hurd,commited 1/4] hurd: Fix lsetxattr return value Samuel Thibault
2024-06-10 20:09 ` [hurd,commited 2/4] hurd: Fix getxattr("gnu.translator") returning ENODATA Samuel Thibault
2024-06-10 20:09 ` [hurd,commited 3/4] hurd: Fix setxattr return value on replacing Samuel Thibault
2024-06-10 20:09 ` [hurd,commited 4/4] hurd: Fix getxattr/listxattr returning ERANGE Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).