Message ID | 20180418160115.16204-6-jkbs@redhat.com |
---|---|
State | Accepted |
Headers | show |
Series | Run Python IDL checks using SSL | expand |
On Wed, Apr 18, 2018 at 06:01:14PM +0200, Jakub Sitnicki wrote: > Encoding from 'unicode' to 'str' that has been added to the Stream class > in commit 2254074e3067 ("python: fix python3 encode/decode on Windows") > conflicts with SSLStream which already contains a quirk for pyopenssl > that does the same thing. > > This results in a double encoding attempt when SSL is used and we crash > and burn due to: > > Traceback (most recent call last): > File "../.././test-ovsdb.py", line 874, in <module> > main(sys.argv) > File "../.././test-ovsdb.py", line 869, in main > func(*args) > File "../.././test-ovsdb.py", line 655, in do_idl > idl_set(idl, command, step) > File "../.././test-ovsdb.py", line 526, in idl_set > status = txn.commit_block() > File "/home/jkbs/src/ovs/python/ovs/db/idl.py", line 1405, in commit_block > status = self.commit() > File "/home/jkbs/src/ovs/python/ovs/db/idl.py", line 1388, in commit > if not self.idl._session.send(msg): > File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 540, in send > return self.rpc.send(msg) > File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 244, in send > self.run() > File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 203, in run > retval = self.stream.send(self.output) > File "/home/jkbs/src/ovs/python/ovs/stream.py", line 808, in send > return super(SSLStream, self).send(buf) > File "/home/jkbs/src/ovs/python/ovs/stream.py", line 391, in send > buf = buf.encode('utf-8') > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 83: ordinal not in range(128) > > Remove the quirk from SSLStream as the base class now does encoding. > > Reported-by: Marcin Mirecki <mmirecki@redhat.com> > Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> I backported this as far as branch-2.7, which are the branches that had the mentioned commit 2254074e3067.
diff --git a/python/ovs/stream.py b/python/ovs/stream.py index c8b96b073..7b15bcd7d 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -801,10 +801,6 @@ class SSLStream(Stream): def send(self, buf): try: - if isinstance(buf, six.text_type): - # Convert to byte stream if the buffer is string type/unicode. - # pyopenssl version 0.14 expects the buffer to be byte string. - buf = buf.encode('utf-8') return super(SSLStream, self).send(buf) except SSL.WantWriteError: return -errno.EAGAIN
Encoding from 'unicode' to 'str' that has been added to the Stream class in commit 2254074e3067 ("python: fix python3 encode/decode on Windows") conflicts with SSLStream which already contains a quirk for pyopenssl that does the same thing. This results in a double encoding attempt when SSL is used and we crash and burn due to: Traceback (most recent call last): File "../.././test-ovsdb.py", line 874, in <module> main(sys.argv) File "../.././test-ovsdb.py", line 869, in main func(*args) File "../.././test-ovsdb.py", line 655, in do_idl idl_set(idl, command, step) File "../.././test-ovsdb.py", line 526, in idl_set status = txn.commit_block() File "/home/jkbs/src/ovs/python/ovs/db/idl.py", line 1405, in commit_block status = self.commit() File "/home/jkbs/src/ovs/python/ovs/db/idl.py", line 1388, in commit if not self.idl._session.send(msg): File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 540, in send return self.rpc.send(msg) File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 244, in send self.run() File "/home/jkbs/src/ovs/python/ovs/jsonrpc.py", line 203, in run retval = self.stream.send(self.output) File "/home/jkbs/src/ovs/python/ovs/stream.py", line 808, in send return super(SSLStream, self).send(buf) File "/home/jkbs/src/ovs/python/ovs/stream.py", line 391, in send buf = buf.encode('utf-8') UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 83: ordinal not in range(128) Remove the quirk from SSLStream as the base class now does encoding. Reported-by: Marcin Mirecki <mmirecki@redhat.com> Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> --- python/ovs/stream.py | 4 ---- 1 file changed, 4 deletions(-) -- 2.14.3