Janneke Nieuwenhuizen writes:

Hi!

>> On Mon, May 18, 2026 at 07:21:10PM -0500, Josh Kilmer wrote:
[..]

>>>* fakeroot correctly forwards the successful call now that errno is 0
>>>* attr_copy_fd overwrites it's size variable with the new result (33),
>>>and reads well past the allocated buffer into a segfault. (It also
>>>skips over it's end pointer and reads much more than 33 bytes, but
>>>that's another issue)
>
> Do you have a recipe, preferrably a shell script example that shows
> this?
>
>>>This appears to have been inadvertently introduced by changes in
>>>#1136815. Some of the introduced !r checks probably need to be changed
>>>to r > 0 to allow positive return values to be returned unmodified.
>
> This makes sense, have you tried that?  I'm happy to try if I can
> reproduce the problem.

Find a patch attached.  Indeed, get/list xattrs return r >=0 upon
success; so !r should be changed to r >0 even.  Please find a patch
attached.

>>>I'd also like to note that it's *not* legal for syscalls to clear
>>>errno, which may now happen if you have a pre-set errno coming into a
>>>modified syscall
>
> Where does this happen that is not OK?  It's true that my patch now
> "tests" getxattr/setxattr to see if it may succeed and I thought that
> was a neat solution.

Haven't addressed this just yet.

>>>  but I've not run into any issues tied to it.
>
> It would be nice to fix it anyway, WDYT?

I was thinking about adding a test for the previous patch but that would
require `attr' to be installed (with getfattr and setfatter) and make
that a new (optional) dependency.  WDYT?

Greetings,
Janneke

>From ebf5287faf86e6462fd056659249a70ebebd6ac2 Mon Sep 17 00:00:00 2001
From: Janneke Nieuwenhuizen <[email protected]>
Date: Tue, 19 May 2026 07:13:20 +0200
Subject: [PATCH] Respect r > 0 success values for get/list xattrs, #closes:
 1137058.

---
 libfakeroot.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libfakeroot.c b/libfakeroot.c
index 4406098..4cb1ebf 100644
--- a/libfakeroot.c
+++ b/libfakeroot.c
@@ -1908,7 +1908,7 @@ ssize_t getxattr(const char *path, const char *name, void *value, size_t size)
   if (fakeroot_disabled || user_xattr_p(name)) {
     r = next_getxattr(path, name, value, size);
     if (fakeroot_disabled
-        || !r
+        || r >= 0
         || (errno != EPERM && errno != EOPNOTSUPP))
       return r;
     errno = 0;
@@ -1936,7 +1936,7 @@ ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size)
   if (fakeroot_disabled || user_xattr_p(name)) {
     r = next_lgetxattr(path, name, value, size);
     if (fakeroot_disabled
-        || !r
+        || r >= 0
         || (errno != EPERM && errno != EOPNOTSUPP))
       return r;
     errno = 0;
@@ -1964,7 +1964,7 @@ ssize_t fgetxattr(int fd, const char *name, void *value, size_t size)
   if (fakeroot_disabled || user_xattr_p(name)) {
     r = next_fgetxattr(fd, name, value, size);
     if (fakeroot_disabled
-        || !r
+        || r >= 0
         || (errno != EPERM && errno != EOPNOTSUPP))
       return r;
     errno = 0;
@@ -1991,7 +1991,7 @@ ssize_t listxattr(const char *path, char *list, size_t size)
 
   r = next_listxattr(path, list, size);
   if (fakeroot_disabled
-      || !r
+      || r >= 0
       || (errno != EPERM && errno != EOPNOTSUPP))
     return r;
   errno = 0;
@@ -2017,7 +2017,7 @@ ssize_t llistxattr(const char *path, char *list, size_t size)
 
   r = next_llistxattr(path, list, size);
   if (fakeroot_disabled
-      || !r
+      || r >= 0
       || (errno != EPERM && errno != EOPNOTSUPP))
     return r;
   errno = 0;
@@ -2043,7 +2043,7 @@ ssize_t flistxattr(int fd, char *list, size_t size)
 
   r = next_flistxattr(fd, list, size);
   if (fakeroot_disabled
-      || !r
+      || r >= 0
       || (errno != EPERM && errno != EOPNOTSUPP))
     return r;
   errno = 0;
-- 
2.54.0

-- 
Janneke Nieuwenhuizen <[email protected]>  | GNU LilyPond https://LilyPond.org
Freelance IT https://www.JoyOfSource.com | AvatarĀ® https://AvatarAcademy.com

Reply via email to