Skip to content

Commit

Permalink
Fix crash when serving non-canonalized endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
klzgrad committed Jun 28, 2022
1 parent e12009d commit c9a374f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/net/socket/client_socket_pool_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ int InitSocketHandleForWebSocketRequest(
std::move(callback), proxy_auth_callback);
}

int InitSocketHandleForRawConnect2(const HostPortPair& endpoint,
int InitSocketHandleForRawConnect2(url::SchemeHostPort endpoint,
HttpNetworkSession* session,
int request_load_flags,
RequestPriority request_priority,
Expand All @@ -289,9 +289,8 @@ int InitSocketHandleForRawConnect2(const HostPortPair& endpoint,
CompletionOnceCallback callback) {
DCHECK(socket_handle);
return InitSocketPoolHelper(
{"http", endpoint.HostForURL(), endpoint.port()}, request_load_flags,
request_priority, session, proxy_info, ssl_config_for_origin,
ssl_config_for_proxy,
std::move(endpoint), request_load_flags, request_priority, session,
proxy_info, ssl_config_for_origin, ssl_config_for_proxy,
/*is_for_websockets=*/true, privacy_mode,
std::move(network_isolation_key), SecureDnsPolicy::kDisable, SocketTag(),
net_log, 0, socket_handle, HttpNetworkSession::NORMAL_SOCKET_POOL,
Expand Down
2 changes: 1 addition & 1 deletion src/net/socket/client_socket_pool_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int InitSocketHandleForWebSocketRequest(
const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback);

NET_EXPORT int InitSocketHandleForRawConnect2(
const HostPortPair& endpoint,
url::SchemeHostPort endpoint,
HttpNetworkSession* session,
int request_load_flags,
RequestPriority request_priority,
Expand Down
12 changes: 9 additions & 3 deletions src/net/tools/naive/naive_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/privacy_mode.h"
#include "net/base/url_util.h"
#include "net/proxy_resolution/proxy_info.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_manager.h"
Expand All @@ -27,6 +28,7 @@
#include "net/tools/naive/http_proxy_socket.h"
#include "net/tools/naive/redirect_resolver.h"
#include "net/tools/naive/socks5_server_socket.h"
#include "url/scheme_host_port.h"

#if defined(OS_LINUX)
#include <linux/netfilter_ipv4.h>
Expand Down Expand Up @@ -243,16 +245,20 @@ int NaiveConnection::DoConnectServer() {
#endif
}

if (origin.IsEmpty()) {
LOG(ERROR) << "Connection " << id_ << " to invalid origin";
url::CanonHostInfo host_info;
url::SchemeHostPort endpoint(
"http", CanonicalizeHost(origin.host(), &host_info), origin.port(),
url::SchemeHostPort::ALREADY_CANONICALIZED);
if (!endpoint.IsValid()) {
LOG(ERROR) << "Connection " << id_ << " to invalid origin " << origin.ToString();
return ERR_ADDRESS_INVALID;
}

LOG(INFO) << "Connection " << id_ << " to " << origin.ToString();

// Ignores socket limit set by socket pool for this type of socket.
return InitSocketHandleForRawConnect2(
origin, session_, LOAD_IGNORE_LIMITS, MAXIMUM_PRIORITY, proxy_info_,
std::move(endpoint), session_, LOAD_IGNORE_LIMITS, MAXIMUM_PRIORITY, proxy_info_,
server_ssl_config_, proxy_ssl_config_, PRIVACY_MODE_DISABLED,
network_isolation_key_, net_log_, server_socket_handle_.get(),
io_callback_);
Expand Down

0 comments on commit c9a374f

Please sign in to comment.