]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rados python bindings: handle xattrs with NULL
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 25 May 2011 18:01:16 +0000 (11:01 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 25 May 2011 18:01:16 +0000 (11:01 -0700)
Handle extended attributes that contain NULL bytes correctly, rather
than treating everything as zero-terminated C strings.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/pybind/rados.py
src/test/ceph-pybind-test.py

index 29bfd8e891307dfb4775596f85cc0c68c9edbae4..205b04d92310799ad68790308ffda2528f18d3aa 100755 (executable)
@@ -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()
index 4deeca626901f361ce0df647335761f606d83653..a358868d878ea4e5c32bcf668d238d3845f292b2 100755 (executable)
@@ -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")