You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sh...@apache.org on 2018/12/04 21:34:08 UTC

[trafficserver] branch master updated: Change serverName member back to const char * to avoid crash.

This is an automated email from the ASF dual-hosted git repository.

shinrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new e215d4d  Change serverName member back to const char * to avoid crash.
e215d4d is described below

commit e215d4dc5d0179c34f17f3bf105ee8519aa7dd9a
Author: Susan Hinrichs <sh...@oath.com>
AuthorDate: Tue Dec 4 15:31:09 2018 +0000

    Change serverName member back to const char * to avoid crash.
---
 iocore/net/P_SSLNetVConnection.h | 6 +++++-
 iocore/net/SSLUtils.cc           | 8 +++++---
 proxy/http/HttpSM.cc             | 4 ++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/iocore/net/P_SSLNetVConnection.h b/iocore/net/P_SSLNetVConnection.h
index e2b7fdc..144cf37 100644
--- a/iocore/net/P_SSLNetVConnection.h
+++ b/iocore/net/P_SSLNetVConnection.h
@@ -361,7 +361,11 @@ public:
   ink_hrtime sslHandshakeEndTime   = 0;
   ink_hrtime sslLastWriteTime      = 0;
   int64_t sslTotalBytesSent        = 0;
-  std::string serverName;
+  // The serverName is either a pointer to the name fetched from the
+  // SSL object or the empty string.  Therefore, we do not allocate
+  // extra memory for this value.  If plugins in the future can set the
+  // serverName value, this strategy will have to change.
+  const char *serverName = nullptr;
 
   /// Set by asynchronous hooks to request a specific operation.
   SslVConnOp hookOpRequested = SSL_HOOK_OP_DEFAULT;
diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc
index f68c522..2df2374 100644
--- a/iocore/net/SSLUtils.cc
+++ b/iocore/net/SSLUtils.cc
@@ -472,9 +472,11 @@ ssl_servername_only_callback(SSL *ssl, int * /* ad */, void * /*arg*/)
   SSLNetVConnection *netvc = SSLNetVCAccess(ssl);
   netvc->callHooks(TS_EVENT_SSL_SERVERNAME);
 
-  const char *name  = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
-  netvc->serverName = std::string{name ? name : ""};
-  int ret           = PerformAction(netvc, netvc->serverName.c_str());
+  netvc->serverName = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
+  if (nullptr == netvc->serverName) {
+    netvc->serverName = "";
+  }
+  int ret = PerformAction(netvc, netvc->serverName);
   if (ret != SSL_TLSEXT_ERR_OK) {
     return SSL_TLSEXT_ERR_ALERT_FATAL;
   }
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index b528932..52d4dde 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -583,7 +583,7 @@ HttpSM::setup_blind_tunnel_port()
           t_state.hdr_info.client_request.url_get()->port_set(t_state.state_machine->ua_txn->get_netvc()->get_local_port());
         }
       } else {
-        t_state.hdr_info.client_request.url_get()->host_set(ssl_vc->serverName.c_str(), ssl_vc->serverName.length());
+        t_state.hdr_info.client_request.url_get()->host_set(ssl_vc->serverName, strlen(ssl_vc->serverName));
         t_state.hdr_info.client_request.url_get()->port_set(t_state.state_machine->ua_txn->get_netvc()->get_local_port());
       }
     }
@@ -1394,7 +1394,7 @@ plugins required to work with sni_routing.
           t_state.hdr_info.client_request.url_get()->port_set(t_state.state_machine->ua_txn->get_netvc()->get_local_port());
         }
       } else if (ssl_vc) {
-        t_state.hdr_info.client_request.url_get()->host_set(ssl_vc->serverName.data(), ssl_vc->serverName.length());
+        t_state.hdr_info.client_request.url_get()->host_set(ssl_vc->serverName, strlen(ssl_vc->serverName));
         t_state.hdr_info.client_request.url_get()->port_set(t_state.state_machine->ua_txn->get_netvc()->get_local_port());
       }
     }