Use default port 443 in HTTP CONNECT request (#26331)

* Use default port 443 in HTTP CONNECT request

* s/data/c_str

* Fix use-after-free

* Reviewer comments
pull/25860/head
Yash Tibrewal 4 years ago committed by GitHub
parent 7879498619
commit c8db1091b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/core/ext/filters/client_channel/http_proxy.cc
  2. 4
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  3. 4
      src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc
  4. 4
      src/core/lib/iomgr/resolve_address.cc
  5. 6
      src/core/lib/iomgr/resolve_address.h

@ -36,6 +36,7 @@
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/slice/b64.h"
#include "src/core/lib/uri/uri_parser.h"
@ -107,6 +108,17 @@ done:
return proxy_name;
}
// Adds the default port if target does not contain a port.
std::string MaybeAddDefaultPort(absl::string_view target) {
absl::string_view host;
absl::string_view port;
SplitHostPort(target, &host, &port);
if (port.empty()) {
return JoinHostPort(host, kDefaultSecurePortInt);
}
return std::string(target);
}
class HttpProxyMapper : public ProxyMapperInterface {
public:
bool MapName(const char* server_uri, const grpc_channel_args* args,
@ -118,6 +130,7 @@ class HttpProxyMapper : public ProxyMapperInterface {
*name_to_resolve = GetHttpProxyServer(args, &user_cred);
if (*name_to_resolve == nullptr) return false;
char* no_proxy_str = nullptr;
std::string server_target;
absl::StatusOr<URI> uri = URI::Parse(server_uri);
if (!uri.ok() || uri->path().empty()) {
gpr_log(GPR_ERROR,
@ -173,10 +186,12 @@ class HttpProxyMapper : public ProxyMapperInterface {
if (!use_proxy) goto no_use_proxy;
}
}
server_target =
MaybeAddDefaultPort(absl::StripPrefix(uri->path(), "/")).c_str();
grpc_arg args_to_add[2];
args_to_add[0] = grpc_channel_arg_string_create(
const_cast<char*>(GRPC_ARG_HTTP_CONNECT_SERVER),
const_cast<char*>(absl::StripPrefix(uri->path(), "/").data()));
const_cast<char*>(server_target.c_str()));
if (user_cred != nullptr) {
/* Use base64 encoding for user credentials as stated in RFC 7617 */
char* encoded_user_cred =

@ -60,8 +60,6 @@ namespace grpc_core {
namespace {
const char kDefaultPort[] = "https";
class AresDnsResolver : public Resolver {
public:
explicit AresDnsResolver(ResolverArgs args);
@ -431,7 +429,7 @@ void AresDnsResolver::StartResolvingLocked() {
resolving_ = true;
service_config_json_ = nullptr;
pending_request_ = grpc_dns_lookup_ares_locked(
dns_server_.c_str(), name_to_resolve_.c_str(), kDefaultPort,
dns_server_.c_str(), name_to_resolve_.c_str(), kDefaultSecurePort,
interested_parties_, &on_resolved_, &addresses_,
enable_srv_queries_ ? &balancer_addresses_ : nullptr,
request_service_config_ ? &service_config_json_ : nullptr,

@ -48,8 +48,6 @@ namespace grpc_core {
namespace {
const char kDefaultPort[] = "https";
class NativeDnsResolver : public Resolver {
public:
explicit NativeDnsResolver(ResolverArgs args);
@ -276,7 +274,7 @@ void NativeDnsResolver::StartResolvingLocked() {
addresses_ = nullptr;
GRPC_CLOSURE_INIT(&on_resolved_, NativeDnsResolver::OnResolved, this,
grpc_schedule_on_exec_ctx);
grpc_resolve_address(name_to_resolve_.c_str(), kDefaultPort,
grpc_resolve_address(name_to_resolve_.c_str(), kDefaultSecurePort,
interested_parties_, &on_resolved_, &addresses_);
last_resolution_timestamp_ = grpc_core::ExecCtx::Get()->Now();
}

@ -21,6 +21,10 @@
#include <grpc/support/alloc.h>
#include "src/core/lib/iomgr/resolve_address.h"
namespace grpc_core {
const char* kDefaultSecurePort = "https";
} // namespace grpc_core
grpc_address_resolver_vtable* grpc_resolve_address_impl;
void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable) {

@ -49,6 +49,12 @@ struct grpc_resolved_addresses {
size_t naddrs;
grpc_resolved_address* addrs;
};
namespace grpc_core {
extern const char* kDefaultSecurePort;
constexpr int kDefaultSecurePortInt = 443;
} // namespace grpc_core
typedef struct grpc_address_resolver_vtable {
void (*resolve_address)(const char* addr, const char* default_port,
grpc_pollset_set* interested_parties,

Loading…
Cancel
Save