From: Eric Garver Date: Fri, 10 May 2019 12:29:47 +0000 (-0400) Subject: py: fix missing decode/encode of strings X-Git-Tag: v0.9.1~76 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47ffae232aeaadca37293861d52a11f907d6b768;p=thirdparty%2Fnftables.git py: fix missing decode/encode of strings When calling ffi functions, if the string is unicode we need to convert to utf-8. Then convert back for any output we receive. Fixes: 586ad210368b7 ("libnftables: Implement JSON parser") Signed-off-by: Eric Garver Signed-off-by: Pablo Neira Ayuso --- diff --git a/py/nftables.py b/py/nftables.py index f0716357..33cd2dfd 100644 --- a/py/nftables.py +++ b/py/nftables.py @@ -352,9 +352,16 @@ class Nftables: output -- a string containing output written to stdout error -- a string containing output written to stderr """ + cmdline_is_unicode = False + if not isinstance(cmdline, bytes): + cmdline_is_unicode = True + cmdline = cmdline.encode("utf-8") rc = self.nft_run_cmd_from_buffer(self.__ctx, cmdline) output = self.nft_ctx_get_output_buffer(self.__ctx) error = self.nft_ctx_get_error_buffer(self.__ctx) + if cmdline_is_unicode: + output = output.decode("utf-8") + error = error.decode("utf-8") return (rc, output, error)