From f76d5d6fe6a9f92b1ec17191f5504e2f61e0ff28 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Wed, 25 Nov 2015 21:37:23 -0800 Subject: [PATCH] pybind: decode empty string in conf_parse_argv() correctly 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 --- src/pybind/rados.py | 3 +-- src/test/pybind/test_rados.py | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pybind/rados.py b/src/pybind/rados.py index 81aa4094fe7f9..47a03a14555be 100644 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -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 diff --git a/src/test/pybind/test_rados.py b/src/test/pybind/test_rados.py index 9a5f15762aec2..79cb0ff21d018 100644 --- a/src/test/pybind/test_rados.py +++ b/src/test/pybind/test_rados.py @@ -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): -- 2.39.5