From 0af182baa2f35d91b8dfaf0b5a8fef06b77dd03a Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 28 Apr 2021 11:32:44 -0400 Subject: applets/web: Fix a use-after-free when passing in the URL string The URL string was being deleted before being used, leading to a use-after-free occurring when it is used afterwards. Fix this by taking the string by const ref to extend its lifetime, ensuring it doesn't get deleted before use. --- src/yuzu/applets/web_browser.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/yuzu/applets/web_browser.cpp') diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp index e482ba029..93e3a4f6f 100644 --- a/src/yuzu/applets/web_browser.cpp +++ b/src/yuzu/applets/web_browser.cpp @@ -102,8 +102,8 @@ QtNXWebEngineView::~QtNXWebEngineView() { StopInputThread(); } -void QtNXWebEngineView::LoadLocalWebPage(std::string_view main_url, - std::string_view additional_args) { +void QtNXWebEngineView::LoadLocalWebPage(const std::string& main_url, + const std::string& additional_args) { is_local = true; LoadExtractedFonts(); @@ -113,12 +113,12 @@ void QtNXWebEngineView::LoadLocalWebPage(std::string_view main_url, SetLastURL("http://localhost/"); StartInputThread(); - load(QUrl(QUrl::fromLocalFile(QString::fromStdString(std::string(main_url))).toString() + - QString::fromStdString(std::string(additional_args)))); + load(QUrl(QUrl::fromLocalFile(QString::fromStdString(main_url)).toString() + + QString::fromStdString(additional_args))); } -void QtNXWebEngineView::LoadExternalWebPage(std::string_view main_url, - std::string_view additional_args) { +void QtNXWebEngineView::LoadExternalWebPage(const std::string& main_url, + const std::string& additional_args) { is_local = false; SetUserAgent(UserAgent::WebApplet); @@ -127,8 +127,7 @@ void QtNXWebEngineView::LoadExternalWebPage(std::string_view main_url, SetLastURL("http://localhost/"); StartInputThread(); - load(QUrl(QString::fromStdString(std::string(main_url)) + - QString::fromStdString(std::string(additional_args)))); + load(QUrl(QString::fromStdString(main_url) + QString::fromStdString(additional_args))); } void QtNXWebEngineView::SetUserAgent(UserAgent user_agent) { @@ -375,7 +374,7 @@ QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { QtWebBrowser::~QtWebBrowser() = default; void QtWebBrowser::OpenLocalWebPage( - std::string_view local_url, std::function extract_romfs_callback_, + const std::string& local_url, std::function extract_romfs_callback_, std::function callback_) const { extract_romfs_callback = std::move(extract_romfs_callback_); callback = std::move(callback_); @@ -390,7 +389,7 @@ void QtWebBrowser::OpenLocalWebPage( } void QtWebBrowser::OpenExternalWebPage( - std::string_view external_url, + const std::string& external_url, std::function callback_) const { callback = std::move(callback_); -- cgit v1.2.3