]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: decode empty string in conf_parse_argv() correctly 6711/head
authorJosh Durgin <jdurgin@redhat.com>
Thu, 26 Nov 2015 05:37:23 +0000 (21:37 -0800)
committerJosh Durgin <jdurgin@redhat.com>
Thu, 26 Nov 2015 05:42:01 +0000 (21:42 -0800)
cretargs is a array of c_char_p, which means ctypes has already
converted it to python byte strings. decode_cstr() would misinterpret
the empty string as a NULL c_char_p(), and convert it to None by
accident, resulting in errors when running commands like
'ceph config-key put foo ""'.

Since this is the only place we use arrays of c_char_p, just decode
it directly in conf_parse_argv(). Tested with python 2 and 3.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
src/pybind/rados.py
src/test/pybind/test_rados.py

index 81aa4094fe7f9c1604424d237d06a187c7ec58e8..47a03a14555bec9dc555134120aa0526ef8a725a 100644 (file)
@@ -429,8 +429,7 @@ Rados object in state %s." % self.state)
 
         # cretargs was allocated with fixed length; collapse return
         # list to eliminate any missing args
-
-        retargs = [decode_cstr(a) for a in cretargs if a is not None]
+        retargs = [a.decode('utf-8') for a in cretargs if a is not None]
         self.parsed_args = args
         return retargs
 
index 9a5f15762aec2bba98cc8a2a3e91e83040ffc6db..79cb0ff21d018124a393d2a689a09b61ba83f6da 100644 (file)
@@ -33,6 +33,11 @@ def test_ioctx_context_manager():
         with conn.open_ioctx('rbd') as ioctx:
             pass
 
+def test_parse_argv_empty_str():
+    args = ['']
+    r = Rados()
+    eq(args, r.conf_parse_argv(args))
+
 class TestRequires(object):
     @requires(('foo', str), ('bar', int), ('baz', int))
     def _method_plain(self, foo, bar, baz):