From: Amos Jeffries Date: Fri, 6 May 2016 09:39:48 +0000 (+1200) Subject: Fix SIGSEGV in ESIContext response handling X-Git-Tag: SQUID_3_5_18~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5f4f9b31e1a05d1bacfb8a18b1792c7ef2bcf4a;p=thirdparty%2Fsquid.git Fix SIGSEGV in ESIContext response handling HttpReply pointer was being unlocked without heving been locked. Resulting in a double-free. Make it use RefCount instead of manual locking to ensure locked/unlock is always symmetrical. --- diff --git a/src/esi/Context.h b/src/esi/Context.h index ea6abc1940..1f02bca462 100644 --- a/src/esi/Context.h +++ b/src/esi/Context.h @@ -13,6 +13,7 @@ #include "err_type.h" #include "esi/Element.h" #include "esi/Parser.h" +#include "HttpReply.h" #include "http/StatusCode.h" class ESIVarState; @@ -91,7 +92,7 @@ public: err_type errorpage; /* if we error what page to use */ Http::StatusCode errorstatus; /* if we error, what code to return */ char *errormessage; /* error to pass to error page */ - HttpReply *rep; /* buffered until we pass data downstream */ + HttpReply::Pointer rep; /* buffered until we pass data downstream */ ESISegment::Pointer buffered; /* unprocessed data - for whatever reason */ ESISegment::Pointer incoming; /* processed data we are waiting to send, or for diff --git a/src/esi/Esi.cc b/src/esi/Esi.cc index 29f36ee544..994e8e85cf 100644 --- a/src/esi/Esi.cc +++ b/src/esi/Esi.cc @@ -573,7 +573,7 @@ ESIContext::send () #endif - if (!(rep || (outbound.getRaw() && + if (!(rep != NULL || (outbound.getRaw() && outbound->len && (outbound_offset <= outbound->len)))) { debugs(86, 5, "ESIContext::send: Nothing to send."); return 0; @@ -618,18 +618,18 @@ ESIContext::send () flags.clientwantsdata = 0; debugs(86, 5, "ESIContext::send: this=" << this << " Client no longer wants data "); /* Deal with re-entrancy */ - HttpReply *temprep = rep; + HttpReply::Pointer temprep = rep; rep = NULL; /* freed downstream */ - if (temprep && varState) - varState->buildVary (temprep); + if (temprep != NULL && varState) + varState->buildVary(temprep.getRaw()); { StoreIOBuffer tempBuffer; tempBuffer.length = len; tempBuffer.offset = pos - len; tempBuffer.data = next->readBuffer.data; - clientStreamCallback (thisNode, http, temprep, tempBuffer); + clientStreamCallback (thisNode, http, temprep.getRaw(), tempBuffer); } if (len == 0) @@ -1259,7 +1259,7 @@ ESIContext::parse() ++parserState.stackdepth; } - if (rep && !parserState.inited()) + if (rep != NULL && !parserState.inited()) parserState.init(this); /* we have data */ @@ -1398,7 +1398,7 @@ ESIContext::freeResources () { debugs(86, 5, HERE << "Freeing for this=" << this); - HTTPMSGUNLOCK(rep); + rep = NULL; // refcounted finishChildren ();