From 627b4026532bb064257fe81596b4499c103b07b7 Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Wed, 15 Jul 2020 10:56:09 -0700 Subject: [PATCH] Fixed core when sending back a redirect and having an invalid server response --- proxy/http/HttpTransact.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc index 727121e7e20..fe8d2ef3ac1 100644 --- a/proxy/http/HttpTransact.cc +++ b/proxy/http/HttpTransact.cc @@ -1919,22 +1919,27 @@ HttpTransact::OSDNSLookup(State *s) ink_release_assert(s->http_config_param->redirect_actions_map->contains(s->host_db_info.ip(), reinterpret_cast(&x))); action = static_cast(x); } - switch (action) { - case RedirectEnabled::Action::FOLLOW: + + if (action == RedirectEnabled::Action::FOLLOW) { TxnDebug("http_trans", "[OSDNSLookup] Invalid redirect address. Following"); - break; - case RedirectEnabled::Action::REJECT: - TxnDebug("http_trans", "[OSDNSLookup] Invalid redirect address. Rejecting."); + } else if (action == RedirectEnabled::Action::REJECT || s->hdr_info.server_response.valid() == false) { + if (action == RedirectEnabled::Action::REJECT) { + TxnDebug("http_trans", "[OSDNSLookup] Invalid redirect address. Rejecting."); + } else { + // Invalid server response, since we can't copy it we are going to reject + TxnDebug("http_trans", "[OSDNSLookup] Invalid server response. Rejecting."); + Error("Invalid server response. Rejecting."); + } build_error_response(s, HTTP_STATUS_FORBIDDEN, nullptr, "request#syntax_error"); SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_NO_FORWARD); TRANSACT_RETURN(SM_ACTION_SEND_ERROR_CACHE_NOOP, nullptr); - break; - case RedirectEnabled::Action::RETURN: - TxnDebug("http_trans", "[OSDNSLookup] Configured to return on invalid redirect address."); - // fall-through - default: - // Return this 3xx to the client as-is. - TxnDebug("http_trans", "[OSDNSLookup] Invalid redirect address. Returning."); + } else { + // Return this 3xx to the client as-is + if (action == RedirectEnabled::Action::RETURN) { + TxnDebug("http_trans", "[OSDNSLookup] Configured to return on invalid redirect address."); + } else { + TxnDebug("http_trans", "[OSDNSLookup] Invalid redirect address. Returning."); + } build_response_copy(s, &s->hdr_info.server_response, &s->hdr_info.client_response, s->client_info.http_version); TRANSACT_RETURN(SM_ACTION_INTERNAL_CACHE_NOOP, nullptr); }