From 27ee3534011dedaaeb5c85b333394fd5f94f14ca Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 16 Nov 2022 15:28:18 +0100 Subject: [PATCH 1/2] Don't include default message to send_error() Python can provide this for us, so avoid duplication. --- tests/test_websockifyserver.py | 4 ++-- websockify/websockifyserver.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_websockifyserver.py b/tests/test_websockifyserver.py index 4f46cb19..79d1b258 100644 --- a/tests/test_websockifyserver.py +++ b/tests/test_websockifyserver.py @@ -86,7 +86,7 @@ def test_normal_get_with_only_upgrade_returns_error(self, send_error): FakeSocket(b'GET /tmp.txt HTTP/1.1'), '127.0.0.1', server) handler.do_GET() - send_error.assert_called_with(405, ANY) + send_error.assert_called_with(405) @patch('websockify.websockifyserver.WebSockifyRequestHandler.send_error') def test_list_dir_with_file_only_returns_error(self, send_error): @@ -96,7 +96,7 @@ def test_list_dir_with_file_only_returns_error(self, send_error): handler.path = '/' handler.do_GET() - send_error.assert_called_with(404, ANY) + send_error.assert_called_with(404) class WebSockifyServerTestCase(unittest.TestCase): diff --git a/websockify/websockifyserver.py b/websockify/websockifyserver.py index 3e13fa1e..b1905bd6 100644 --- a/websockify/websockifyserver.py +++ b/websockify/websockifyserver.py @@ -250,13 +250,13 @@ def do_GET(self): self.auth_connection() if self.only_upgrade: - self.send_error(405, "Method Not Allowed") + self.send_error(405) else: super().do_GET() def list_directory(self, path): if self.file_only: - self.send_error(404, "No such file") + self.send_error(404) else: return super().list_directory(path) @@ -277,7 +277,7 @@ def do_HEAD(self): self.auth_connection() if self.only_upgrade: - self.send_error(405, "Method Not Allowed") + self.send_error(405) else: super().do_HEAD() From d2affc73b5f40a8a53c839f661dac4f4c4547ede Mon Sep 17 00:00:00 2001 From: Adam Tilghman Date: Wed, 16 Nov 2022 16:35:39 -0800 Subject: [PATCH 2/2] Insert rebinder at the head of the (possibly empty) LD_PRELOAD pathlist, required for use cases relying on other preloaded libraries e.g. nss_wrapper. --- websockify/websocketproxy.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/websockify/websocketproxy.py b/websockify/websocketproxy.py index c636d548..feed588c 100644 --- a/websockify/websocketproxy.py +++ b/websockify/websocketproxy.py @@ -325,8 +325,11 @@ def __init__(self, RequestHandlerClass=ProxyRequestHandler, *args, **kwargs): self.target_port = sock.getsockname()[1] sock.close() + # Insert rebinder at the head of the (possibly empty) LD_PRELOAD pathlist + ld_preloads = filter(None, [ self.rebinder, os.environ.get("LD_PRELOAD", None) ]) + os.environ.update({ - "LD_PRELOAD": self.rebinder, + "LD_PRELOAD": os.pathsep.join(ld_preloads), "REBIND_OLD_PORT": str(kwargs['listen_port']), "REBIND_NEW_PORT": str(self.target_port)})