From 413acfcfd635590abef585e34fcf96b15964b3ed Mon Sep 17 00:00:00 2001 From: Max <41635752+mkarolin@users.noreply.github.com> Date: Wed, 25 Aug 2021 21:53:59 -0400 Subject: [PATCH] Merge pull request #9858 from brave/maxk-cr93fu-fix-webtorrent-crash [cr93 followup] Fix for webtorrent crash. --- ...tcp_server-sockets_tcp_server_api.cc.patch | 23 +++++++++++++++++++ ..._tcp_server-sockets_tcp_server_api.h.patch | 14 +++++++++++ ...sockets_tcp_server-api-background.js.patch | 16 +++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.cc.patch create mode 100644 patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.h.patch create mode 100644 patches/extensions-test-data-sockets_tcp_server-api-background.js.patch diff --git a/patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.cc.patch b/patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.cc.patch new file mode 100644 index 000000000000..285221794881 --- /dev/null +++ b/patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.cc.patch @@ -0,0 +1,23 @@ +diff --git a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc +index fcba8ac797b18084efd5a79ae7cdf25487a61407..abf5c544601b32ca6898f64b9bd3927dceff4a41 100644 +--- a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc ++++ b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.cc +@@ -256,15 +256,15 @@ SocketsTcpServerGetInfoFunction::~SocketsTcpServerGetInfoFunction() = default; + ExtensionFunction::ResponseAction SocketsTcpServerGetInfoFunction::Work() { + std::unique_ptr params = + sockets_tcp_server::GetInfo::Params::Create(*args_); +- EXTENSION_FUNCTION_VALIDATE(params_.get()); ++ EXTENSION_FUNCTION_VALIDATE(params.get()); + +- ResumableTCPServerSocket* socket = GetTcpSocket(params_->socket_id); ++ ResumableTCPServerSocket* socket = GetTcpSocket(params->socket_id); + if (!socket) { + return RespondNow(Error(kSocketNotFoundError)); + } + + sockets_tcp_server::SocketInfo socket_info = +- CreateSocketInfo(params_->socket_id, socket); ++ CreateSocketInfo(params->socket_id, socket); + return RespondNow( + ArgumentList(sockets_tcp_server::GetInfo::Results::Create(socket_info))); + } diff --git a/patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.h.patch b/patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.h.patch new file mode 100644 index 000000000000..aea55cef8541 --- /dev/null +++ b/patches/extensions-browser-api-sockets_tcp_server-sockets_tcp_server_api.h.patch @@ -0,0 +1,14 @@ +diff --git a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h +index 39d68080d449de6a3de282afe4d6335652402e06..d60fa8bbe677c83037f26c5b3cfd286d6a79bd8a 100644 +--- a/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h ++++ b/extensions/browser/api/sockets_tcp_server/sockets_tcp_server_api.h +@@ -134,9 +134,6 @@ class SocketsTcpServerGetInfoFunction : public TCPServerSocketApiFunction { + + // SocketApiFunction: + ResponseAction Work() override; +- +- private: +- std::unique_ptr params_; + }; + + class SocketsTcpServerGetSocketsFunction : public TCPServerSocketApiFunction { diff --git a/patches/extensions-test-data-sockets_tcp_server-api-background.js.patch b/patches/extensions-test-data-sockets_tcp_server-api-background.js.patch new file mode 100644 index 000000000000..6fbf01aae0b0 --- /dev/null +++ b/patches/extensions-test-data-sockets_tcp_server-api-background.js.patch @@ -0,0 +1,16 @@ +diff --git a/extensions/test/data/sockets_tcp_server/api/background.js b/extensions/test/data/sockets_tcp_server/api/background.js +index 8a2ff5ee95c74b1cc4e9a9e6bf62db889fe83309..f25b1e7dead44c84bc3019103a95a3c9101f9a91 100644 +--- a/extensions/test/data/sockets_tcp_server/api/background.js ++++ b/extensions/test/data/sockets_tcp_server/api/background.js +@@ -43,6 +43,11 @@ var testSocketListening = function() { + function onServerSocketCreate(socketInfo) { + console.log("Server socket created: sd=" + socketInfo.socketId); + socketId = socketInfo.socketId; ++ chrome.sockets.tcpServer.getInfo(socketId, onGetInfo); ++ } ++ ++ function onGetInfo(socketInfo) { ++ chrome.test.assertEq(socketInfo.socketId, socketId); + chrome.sockets.tcpServer.listen(socketId, address, port, onListen); + } +