From: Colin Patrick McCabe Date: Wed, 25 May 2011 18:01:16 +0000 (-0700) Subject: rados python bindings: handle xattrs with NULL X-Git-Tag: v0.29~27^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0adaa6b6ac62b712f7d985d7cf658022d4356dea;p=ceph.git rados python bindings: handle xattrs with NULL Handle extended attributes that contain NULL bytes correctly, rather than treating everything as zero-terminated C strings. Signed-off-by: Colin McCabe --- diff --git a/src/pybind/rados.py b/src/pybind/rados.py index 29bfd8e89130..205b04d92310 100755 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -426,7 +426,7 @@ written." % (self.name, ret, length)) c_char_p(xattr_name), ret_buf, c_size_t(ret_length)) if ret < 0: raise make_ex(ret, "Failed to get xattr %r" % xattr_name) - return ret_buf.value + return ctypes.string_at(ret_buf, ret) def get_xattrs(self, oid): self.require_ioctx_open() diff --git a/src/test/ceph-pybind-test.py b/src/test/ceph-pybind-test.py index 4deeca626901..a358868d878e 100755 --- a/src/test/ceph-pybind-test.py +++ b/src/test/ceph-pybind-test.py @@ -83,6 +83,12 @@ if (found["a"] != "1"): if (found["c"] != "3"): raise RuntimeError("error: expected object abc to have c=3") +foo3_ioctx.set_xattr("def", "zeroholder", "a\0b") +ret = foo3_ioctx.get_xattr("def", "zeroholder") +if (ret != "a\0b"): + raise RuntimeError("error: set_xattr/get_xattr failed with " + + "an extended attribute containing NULL") + # create some snapshots and do stuff with them print "creating snap bjork" foo3_ioctx.create_snap("bjork")