From 2a4478a7adbb8da20a593654ca03676127d2af48 Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Tue, 1 Oct 2024 15:04:54 -0400 Subject: [PATCH] mobile: Fix bugs in the Apple PAC proxy resolver Signed-off-by: Ali Beyad --- .../common/network/apple_pac_proxy_resolver.cc | 13 +++++++------ .../common/network/apple_pac_proxy_resolver.h | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mobile/library/common/network/apple_pac_proxy_resolver.cc b/mobile/library/common/network/apple_pac_proxy_resolver.cc index f8d1fda23720..b3c7fdd20667 100644 --- a/mobile/library/common/network/apple_pac_proxy_resolver.cc +++ b/mobile/library/common/network/apple_pac_proxy_resolver.cc @@ -15,11 +15,9 @@ namespace { // Creates a CFURLRef from a C++ string URL. CFURLRef createCFURL(const std::string& url_string) { - auto cf_url_string = - CFStringCreateWithCString(kCFAllocatorDefault, url_string.c_str(), kCFStringEncodingUTF8); - auto cf_url = CFURLCreateWithString(kCFAllocatorDefault, cf_url_string, /*baseURL=*/nullptr); - CFRelease(cf_url_string); - return cf_url; + return CFURLCreateWithBytes(kCFAllocatorDefault, + reinterpret_cast(url_string.c_str()), + url_string.length(), kCFStringEncodingUTF8, nullptr); } } // namespace @@ -80,10 +78,13 @@ ApplePacProxyResolver::createPacUrlResolverSource(CFURLRef cf_proxy_autoconfigur } void ApplePacProxyResolver::resolveProxies( - const std::string& target_url, const std::string& proxy_autoconfiguration_file_url, + const std::string& proxy_autoconfiguration_file_url, const std::string& target_url, ProxySettingsResolvedCallback proxy_resolution_completed) { CFURLRef cf_target_url = createCFURL(target_url); CFURLRef cf_proxy_autoconfiguration_file_url = createCFURL(proxy_autoconfiguration_file_url); + if (cf_target_url == nullptr || cf_proxy_autoconfiguration_file_url == nullptr) { + return; + } std::unique_ptr completion_callback = std::make_unique(std::move(proxy_resolution_completed)); diff --git a/mobile/library/common/network/apple_pac_proxy_resolver.h b/mobile/library/common/network/apple_pac_proxy_resolver.h index 24d349056506..673e00a6b063 100644 --- a/mobile/library/common/network/apple_pac_proxy_resolver.h +++ b/mobile/library/common/network/apple_pac_proxy_resolver.h @@ -27,13 +27,13 @@ class ApplePacProxyResolver { /** * Resolves proxy for a given URL using proxy auto configuration file that's hosted at a given * URL. - * @param target_url A request URL to resolve the proxy for. * @param proxy_autoconfiguration_file_url A URL at which a proxy configuration file is hosted. + * @param target_url A request URL to resolve the proxy for. * @param proxy_resolution_completed A function that's called with result proxies as its * arguments when proxy resolution completes. */ - void resolveProxies(const std::string& target_url, - const std::string& proxy_autoconfiguration_file_url, + void resolveProxies(const std::string& proxy_autoconfiguration_file_url, + const std::string& target_url, ProxySettingsResolvedCallback proxy_resolution_completed); protected: