From 0f3066abbb1b65e9cde8df9499483bf0768c273e Mon Sep 17 00:00:00 2001 From: David Mulder Date: Mon, 6 Jul 2020 08:13:57 -0600 Subject: [PATCH] gpo: Properly decode utf-8/16 inf files from bytes This code was python 2 specific (string handling has changed dramatically in python 3), and didn't correctly decode utf-16 in python3. We should instead read the file as bytes, then attempt a utf-8 decode (the default), and try utf-16 if encountering a decode failure. The existing code actually throws an exception on the initial file read when the data is utf-16, since it tries to decode the bytes to a utf-8 string. Signed-off-by: David Mulder Reviewed-by: Douglas Bagnall --- python/samba/gpclass.py | 6 +++--- selftest/knownfail.d/gpo | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 selftest/knownfail.d/gpo diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py index cc574e12a42..1831e6e1ebc 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -351,12 +351,12 @@ class gp_ext_setter(object): class gp_inf_ext(gp_ext): def read(self, data_file): - policy = open(data_file, 'r').read() + policy = open(data_file, 'rb').read() inf_conf = ConfigParser() inf_conf.optionxform = str try: - inf_conf.readfp(StringIO(policy)) - except: + inf_conf.readfp(StringIO(policy.decode())) + except UnicodeDecodeError: inf_conf.readfp(StringIO(policy.decode('utf-16'))) return inf_conf diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo deleted file mode 100644 index d2e80b6cc9a..00000000000 --- a/selftest/knownfail.d/gpo +++ /dev/null @@ -1 +0,0 @@ -samba.tests.gpo.samba.tests.gpo.GPOTests.test_gp_inf_ext_utf -- 2.47.3