فهرست منبع

fuse: fix crash if empty (None) xattr is read

Marian Beermann 8 سال پیش
والد
کامیت
d9681c6b15
2فایلهای تغییر یافته به همراه5 افزوده شده و 2 حذف شده
  1. 1 1
      borg/fuse.py
  2. 4 1
      borg/testsuite/archiver.py

+ 1 - 1
borg/fuse.py

@@ -245,7 +245,7 @@ class FuseOperations(llfuse.Operations):
     def getxattr(self, inode, name, ctx=None):
     def getxattr(self, inode, name, ctx=None):
         item = self.get_item(inode)
         item = self.get_item(inode)
         try:
         try:
-            return item.get(b'xattrs', {})[name]
+            return item.get(b'xattrs', {})[name] or b''
         except KeyError:
         except KeyError:
             raise llfuse.FUSEError(llfuse.ENOATTR) from None
             raise llfuse.FUSEError(llfuse.ENOATTR) from None
 
 

+ 4 - 1
borg/testsuite/archiver.py

@@ -289,6 +289,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
             # into "fakeroot space". Because the xattrs exposed by borgfs are these of an underlying file
             # into "fakeroot space". Because the xattrs exposed by borgfs are these of an underlying file
             # (from fakeroots point of view) they are invisible to the test process inside the fakeroot.
             # (from fakeroots point of view) they are invisible to the test process inside the fakeroot.
             xattr.setxattr(os.path.join(self.input_path, 'fusexattr'), 'user.foo', b'bar')
             xattr.setxattr(os.path.join(self.input_path, 'fusexattr'), 'user.foo', b'bar')
+            xattr.setxattr(os.path.join(self.input_path, 'fusexattr'), 'user.empty', b'')
             # XXX this always fails for me
             # XXX this always fails for me
             # ubuntu 14.04, on a TMP dir filesystem with user_xattr, using fakeroot
             # ubuntu 14.04, on a TMP dir filesystem with user_xattr, using fakeroot
             # same for newer ubuntu and centos.
             # same for newer ubuntu and centos.
@@ -1159,8 +1160,10 @@ class ArchiverTestCase(ArchiverTestCaseBase):
                 in_fn = 'input/fusexattr'
                 in_fn = 'input/fusexattr'
                 out_fn = os.path.join(mountpoint, 'input', 'fusexattr')
                 out_fn = os.path.join(mountpoint, 'input', 'fusexattr')
                 if not xattr.XATTR_FAKEROOT and xattr.is_enabled(self.input_path):
                 if not xattr.XATTR_FAKEROOT and xattr.is_enabled(self.input_path):
-                    assert no_selinux(xattr.listxattr(out_fn)) == ['user.foo', ]
+                    assert sorted(no_selinux(xattr.listxattr(out_fn))) == ['user.empty', 'user.foo', ]
                     assert xattr.getxattr(out_fn, 'user.foo') == b'bar'
                     assert xattr.getxattr(out_fn, 'user.foo') == b'bar'
+                    # Special case: getxattr returns None (not b'') when reading an empty xattr.
+                    assert xattr.getxattr(out_fn, 'user.empty') is None
                 else:
                 else:
                     assert xattr.listxattr(out_fn) == []
                     assert xattr.listxattr(out_fn) == []
                     try:
                     try: