You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2015/08/06 06:06:45 UTC

[09/14] trafficserver git commit: TS-3658 ASAN triggers when using the escalate.so plugin

TS-3658 ASAN triggers when using the escalate.so plugin


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/9e8800c5
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/9e8800c5
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/9e8800c5

Branch: refs/heads/6.0.x
Commit: 9e8800c5f648e4902c522087e88d9ea806a1de4f
Parents: fe64607
Author: Leif Hedstrom <zw...@apache.org>
Authored: Wed Aug 5 20:08:52 2015 -0600
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Wed Aug 5 20:08:56 2015 -0600

----------------------------------------------------------------------
 proxy/http/HttpSM.cc | 50 +++++++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9e8800c5/proxy/http/HttpSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 9da84b5..8ba5eaa 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -7527,38 +7527,33 @@ HttpSM::redirect_request(const char *redirect_url, const int redirect_len)
 
     if (host != NULL) {
       int port = clientUrl.port_get();
-      char buf[host_len + 7];
-
       int redirectSchemeLen;
       const char *redirectScheme = clientUrl.scheme_get(&redirectSchemeLen);
+
       if (redirectScheme == NULL) {
         clientUrl.scheme_set(scheme_str, scheme_len);
-        DebugSM("http_redirect", "[HttpSM::redirect_request] hsot without scheme %s", buf);
+        DebugSM("http_redirect", "[HttpSM::redirect_request] URL without scheme %.*s", redirectSchemeLen, redirectScheme);
       }
 
       if (noPortInHost) {
         int redirectSchemeIdx = clientUrl.scheme_get_wksidx();
-
         bool defaultPort =
           (((redirectSchemeIdx == URL_WKSIDX_HTTP) && (port == 80)) || ((redirectSchemeIdx == URL_WKSIDX_HTTPS) && (port == 443)));
 
-        if (!defaultPort)
+        if (!defaultPort) {
           noPortInHost = false;
+        }
       }
 
-      ink_strlcpy(buf, host, host_len + 1);
-
       if (!noPortInHost) {
-        char port_buf[6]; // handle upto 5 digit port
-        buf[host_len++] = ':';
-        buf[host_len] = '\0';
+        char buf[host_len + 7]; // 5 + 1 + 1 ("12345" + ':' + '\0')
 
-        host_len += ink_small_itoa(port, port_buf, sizeof(port_buf));
-        ink_strlcat(buf, port_buf, sizeof(buf));
+        host_len = snprintf(buf, host_len + 7, "%.*s:%d", host_len, host, port);
+        t_state.hdr_info.client_request.value_set(MIME_FIELD_HOST, MIME_LEN_HOST, buf, host_len);
+      } else {
+        t_state.hdr_info.client_request.value_set(MIME_FIELD_HOST, MIME_LEN_HOST, host, host_len);
       }
-
       t_state.hdr_info.client_request.m_target_cached = false;
-      t_state.hdr_info.client_request.value_set(MIME_FIELD_HOST, MIME_LEN_HOST, buf, host_len);
     } else {
       // the client request didn't have a host, so use the current origin host
       if (valid_origHost) {
@@ -7566,18 +7561,15 @@ HttpSM::redirect_request(const char *redirect_url, const int redirect_len)
 
         // the client request didn't have a host, so use the current origin host
         DebugSM("http_redirect", "[HttpSM::redirect_request] keeping client request host %s://%s", next_hop_scheme, origHost);
-        char *origHost1 = strtok_r(origHost, ":", &saveptr);
-        if (origHost1 == NULL) {
+        char *origHostNoPort = strtok_r(origHost, ":", &saveptr);
+
+        if (origHostNoPort == NULL) {
           goto LhostError;
         }
-        origHost_len = strlen(origHost1);
-        int origHostPort_len = origHost_len;
-        char buf[origHostPort_len + 7];
-        ink_strlcpy(buf, origHost1, origHost_len + 1);
 
+        host_len = strlen(origHostNoPort);
         if (noPortInHost) {
           int redirectSchemeIdx = t_state.next_hop_scheme;
-
           bool defaultPort = (((redirectSchemeIdx == URL_WKSIDX_HTTP) && (origPort == 80)) ||
                               ((redirectSchemeIdx == URL_WKSIDX_HTTPS) && (origPort == 443)));
 
@@ -7586,20 +7578,18 @@ HttpSM::redirect_request(const char *redirect_url, const int redirect_len)
         }
 
         if (!noPortInHost) {
-          char port_buf[6]; // handle upto 5 digit port
-          buf[origHostPort_len++] = ':';
-          buf[origHostPort_len] = '\0';
-          origHostPort_len += ink_small_itoa(origPort, port_buf, sizeof(port_buf));
-          ink_strlcat(buf, port_buf, sizeof(buf));
+          char buf[host_len + 7]; // 5 + 1 + 1 ("12345" + ':' + '\0')
+
+          host_len = snprintf(buf, host_len + 7, "%s:%d", origHostNoPort, origPort);
+          t_state.hdr_info.client_request.value_set(MIME_FIELD_HOST, MIME_LEN_HOST, buf, host_len);
+        } else {
+          t_state.hdr_info.client_request.value_set(MIME_FIELD_HOST, MIME_LEN_HOST, origHostNoPort, host_len);
         }
 
+        // Cleanup of state etc.
         url_nuke_proxy_stuff(clientUrl.m_url_impl);
         url_nuke_proxy_stuff(t_state.hdr_info.client_request.m_url_cached.m_url_impl);
         t_state.hdr_info.client_request.method_set(origMethod, origMethod_len);
-        if (noPortInHost)
-          t_state.hdr_info.client_request.value_set(MIME_FIELD_HOST, MIME_LEN_HOST, buf, origHost_len);
-        else
-          t_state.hdr_info.client_request.value_set(MIME_FIELD_HOST, MIME_LEN_HOST, buf, origHostPort_len);
         t_state.hdr_info.client_request.m_target_cached = false;
         clientUrl.scheme_set(scheme_str, scheme_len);
       } else {