diff --git a/proxy/http/HttpSessionManager.cc b/proxy/http/HttpSessionManager.cc index 38a05a3a15b..bfcf334ef9a 100644 --- a/proxy/http/HttpSessionManager.cc +++ b/proxy/http/HttpSessionManager.cc @@ -155,11 +155,11 @@ ServerSessionPool::acquireSession(sockaddr const *addr, CryptoHash const &hostna // Not fixed on FreeBSD as of llvm 6.0.1. std::tie(first, last) = static_cast(m_fqdn_pool.equal_range(hostname_hash)); while (last != first) { - --last; - if (port == ats_ip_port_cast(last->get_server_ip()) && - (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_SNI) || validate_sni(sm, last->get_netvc())) && - (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTSNISYNC) || validate_host_sni(sm, last->get_netvc())) && - (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_CERT) || validate_cert(sm, last->get_netvc()))) { + Http1ServerSession *curr = --last; + if (curr && (port == ats_ip_port_cast(curr->get_server_ip())) && + (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_SNI) || validate_sni(sm, curr->get_netvc())) && + (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTSNISYNC) || validate_host_sni(sm, curr->get_netvc())) && + (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_CERT) || validate_cert(sm, curr->get_netvc()))) { zret = HSM_DONE; break; } @@ -179,11 +179,11 @@ ServerSessionPool::acquireSession(sockaddr const *addr, CryptoHash const &hostna // Note the port is matched as part of the address key so it doesn't need to be checked again. if (match_style & (~TS_SERVER_SESSION_SHARING_MATCH_MASK_IP)) { while (last != first) { - --last; - if ((!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTONLY) || last->hostname_hash == hostname_hash) && - (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_SNI) || validate_sni(sm, last->get_netvc())) && - (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTSNISYNC) || validate_host_sni(sm, last->get_netvc())) && - (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_CERT) || validate_cert(sm, last->get_netvc()))) { + Http1ServerSession *curr = --last; + if (curr && (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTONLY) || curr->hostname_hash == hostname_hash) && + (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_SNI) || validate_sni(sm, curr->get_netvc())) && + (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_HOSTSNISYNC) || validate_host_sni(sm, curr->get_netvc())) && + (!(match_style & TS_SERVER_SESSION_SHARING_MATCH_MASK_CERT) || validate_cert(sm, curr->get_netvc()))) { zret = HSM_DONE; break; }