------------------------------------------------------------ revno: 12413 revision-id: squid3@treenet.co.nz-20121124035637-7z9yevkqfocppjhv parent: squid3@treenet.co.nz-20121124035540-jjnnc65ywk09uew7 committer: Amos Jeffries branch nick: 3.3 timestamp: Fri 2012-11-23 20:56:37 -0700 message: libesi: Various fixes * Mostly uninitialized class member variables * One missing error check in ESI parser (740408) * One potential NULL from dynamic cast fixed (740372) * Several useless/dead code checks Detected by Coverity Scan. Issues 740545, 740408, 740546, 740372, 740547, 740548, 740549, 740550, 740551, 740345, 740346, 740552, 740553, 740554, 740555, 740556, 740557. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20121124035637-7z9yevkqfocppjhv # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # testament_sha1: c0a486fc604dc201bd4c3db81cb0d1fb8be06aa1 # timestamp: 2012-11-24 03:57:56 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.3 # base_revision_id: squid3@treenet.co.nz-20121124035540-\ # jjnnc65ywk09uew7 # # Begin patch === modified file 'src/esi/Context.h' --- src/esi/Context.h 2012-09-20 09:13:58 +0000 +++ src/esi/Context.h 2012-11-24 03:56:37 +0000 @@ -50,7 +50,22 @@ typedef RefCount Pointer; void *operator new (size_t byteCount); void operator delete (void *address); - ESIContext():reading_(true) {} + ESIContext() : + thisNode(NULL), + http(NULL), + errorpage(ERR_NONE), + errorstatus(HTTP_STATUS_NONE), + errormessage(NULL), + rep(NULL), + outbound_offset(0), + readpos(0), + pos(0), + varState(NULL), + cachedASTInUse(false), + reading_(true), + processing(false) { + memset(&flags, 0, sizeof(flags)); + } ~ESIContext(); === modified file 'src/esi/CustomParser.cc' --- src/esi/CustomParser.cc 2012-09-01 14:38:36 +0000 +++ src/esi/CustomParser.cc 2012-11-24 03:56:37 +0000 @@ -68,7 +68,9 @@ return SearchTrie; } -ESICustomParser::ESICustomParser(ESIParserClient *aClient) : theClient (aClient) +ESICustomParser::ESICustomParser(ESIParserClient *aClient) : + theClient(aClient), + lastTag(ESITAG) {} ESICustomParser::~ESICustomParser() @@ -190,7 +192,14 @@ } char *value = equals + 1; - char *end = strchr (value, sep); + char *end = strchr(value, sep); + + if (!end) { + error = "Missing attribute ending separator ("; + error.append(sep); + error.append(")"); + return false; + } attributes.push_back(value); *end = '\0'; attribute = end + 1; === modified file 'src/esi/Esi.cc' --- src/esi/Esi.cc 2012-10-04 09:14:06 +0000 +++ src/esi/Esi.cc 2012-11-24 03:56:37 +0000 @@ -968,7 +968,10 @@ return stack[stackdepth-1]; } -ESIContext::ParserState::ParserState() : inited_ (false) +ESIContext::ParserState::ParserState() : + stackdepth(0), + parsing(0), + inited_(false) {} bool @@ -1554,6 +1557,7 @@ esiLiteral::esiLiteral(ESIContext *context, const char *s, int numberOfCharacters) { assert (s); + flags.donevars = 0; buffer = new ESISegment; ESISegment::Pointer local = buffer; size_t start = 0; @@ -1570,7 +1574,7 @@ remainingCharacters -= len; } - varState = cbdataReference (context->varState); + varState = cbdataReference(context->varState); } void @@ -1705,11 +1709,15 @@ debugs(86, 5, "esiTry::~esiTry " << this); } -esiTry::esiTry(esiTreeParentPtr aParent) : parent (aParent) , exceptbuffer(NULL) -{} +esiTry::esiTry(esiTreeParentPtr aParent) : + parent(aParent), + exceptbuffer(NULL) +{ + memset(&flags, 0, sizeof(flags)); +} void -esiTry::render (ESISegment::Pointer output) +esiTry::render(ESISegment::Pointer output) { /* Try renders from it's children */ assert (this); @@ -2087,8 +2095,8 @@ return; for (size_t counter = 0; counter < elements.size(); ++counter) { - if ((dynamic_cast(elements[counter].getRaw()))-> - testsTrue()) { + const esiWhen *el = dynamic_cast(elements[counter].getRaw()); + if (el && el->testsTrue()) { chosenelement = counter; debugs (86,3, "esiChooseAdd: Chose element " << counter + 1); return; @@ -2325,9 +2333,12 @@ } /* esiWhen */ -esiWhen::esiWhen (esiTreeParentPtr aParent, int attrcount, const char **attr,ESIVarState *aVar) : esiSequence (aParent) +esiWhen::esiWhen(esiTreeParentPtr aParent, int attrcount, const char **attr,ESIVarState *aVar) : + esiSequence(aParent), + testValue(false), + unevaluatedExpression(NULL), + varState(NULL) { - varState = NULL; char const *expression = NULL; for (int loopCounter = 0; loopCounter < attrcount && attr[loopCounter]; loopCounter += 2) { @@ -2370,7 +2381,7 @@ if (!unevaluatedExpression) return; - assert (varState); + assert(varState); varState->feedData(unevaluatedExpression, strlen (unevaluatedExpression)); @@ -2381,14 +2392,14 @@ safe_free (expression); } -esiWhen::esiWhen(esiWhen const &old) : esiSequence (old) +esiWhen::esiWhen(esiWhen const &old) : + esiSequence(old), + testValue(false), + unevaluatedExpression(NULL), + varState(NULL) { - unevaluatedExpression = NULL; - if (old.unevaluatedExpression) unevaluatedExpression = xstrdup(old.unevaluatedExpression); - - varState = NULL; } ESIElement::Pointer === modified file 'src/esi/Expression.cc' --- src/esi/Expression.cc 2012-09-01 14:38:36 +0000 +++ src/esi/Expression.cc 2012-11-24 03:56:37 +0000 @@ -293,10 +293,6 @@ rv = stack[whereAmI - 1].value.integral || stack[whereAmI + 1].value.integral; - if (rv == -2) - /* invalid comparison */ - return 1; - stackpop(stack, depth); /* arg rhs */ stackpop(stack, depth); /* me */ @@ -344,10 +340,6 @@ rv = stack[whereAmI - 1].value.integral && stack[whereAmI + 1].value.integral; - if (rv == -2) - /* invalid comparison */ - return 1; - stackpop(stack, depth); /* arg rhs */ stackpop(stack, depth); /* me */ === modified file 'src/esi/Include.cc' --- src/esi/Include.cc 2012-09-01 14:38:36 +0000 +++ src/esi/Include.cc 2012-11-24 03:56:37 +0000 @@ -299,9 +299,15 @@ return result; } -ESIInclude::ESIInclude(ESIInclude const &old) : parent (NULL), started (false), sent (false) +ESIInclude::ESIInclude(ESIInclude const &old) : + varState(NULL), + srcurl(NULL), + alturl(NULL), + parent(NULL), + started(false), + sent(false) { - varState = NULL; + memset(&flags, 0, sizeof(flags)); flags.onerrorcontinue = old.flags.onerrorcontinue; if (old.srcurl) @@ -344,12 +350,18 @@ tempheaders.clean(); } -ESIInclude::ESIInclude (esiTreeParentPtr aParent, int attrcount, char const **attr, ESIContext *aContext) : parent (aParent), started (false), sent (false) +ESIInclude::ESIInclude(esiTreeParentPtr aParent, int attrcount, char const **attr, ESIContext *aContext) : + varState(NULL), + srcurl(NULL), + alturl(NULL), + parent(aParent), + started(false), + sent(false) { - int i; assert (aContext); + memset(&flags, 0, sizeof(flags)); - for (i = 0; i < attrcount && attr[i]; i += 2) { + for (int i = 0; i < attrcount && attr[i]; i += 2) { if (!strcmp(attr[i],"src")) { /* Start a request for thisNode url */ debugs(86, 5, "ESIIncludeNew: Requesting source '" << attr[i+1] << "'"); === modified file 'src/esi/Sequence.cc' --- src/esi/Sequence.cc 2012-09-01 14:38:36 +0000 +++ src/esi/Sequence.cc 2012-11-24 03:56:37 +0000 @@ -52,8 +52,19 @@ debugs(86, 5, "esiSequence::~esiSequence " << this); } -esiSequence::esiSequence(esiTreeParentPtr aParent, bool incrementalFlag) : elements(), parent (aParent), mayFail_(true), failed (false), provideIncrementalData (incrementalFlag), processing (false), processingResult (ESI_PROCESS_COMPLETE), nextElementToProcess_ (0) -{} +esiSequence::esiSequence(esiTreeParentPtr aParent, bool incrementalFlag) : + elements(), + processedcount(0), + parent(aParent), + mayFail_(true), + failed(false), + provideIncrementalData(incrementalFlag), + processing(false), + processingResult(ESI_PROCESS_COMPLETE), + nextElementToProcess_(0) +{ + memset(&flags, 0, sizeof(flags)); +} size_t esiSequence::nextElementToProcess() const @@ -329,11 +340,17 @@ parent = NULL; } -esiSequence::esiSequence(esiSequence const &old) - : processedcount (0), mayFail_(old.mayFail_), failed (old.failed), provideIncrementalData (old.provideIncrementalData), processing (false), nextElementToProcess_ (0) +esiSequence::esiSequence(esiSequence const &old) : + processedcount(0), + parent(NULL), + mayFail_(old.mayFail_), + failed(old.failed), + provideIncrementalData(old.provideIncrementalData), + processing(false), + processingResult(ESI_PROCESS_COMPLETE), + nextElementToProcess_(0) { flags.dovars = old.flags.dovars; - parent = NULL; } void === modified file 'src/esi/VarState.cc' --- src/esi/VarState.cc 2012-09-01 14:38:36 +0000 +++ src/esi/VarState.cc 2012-11-24 03:56:37 +0000 @@ -291,9 +291,12 @@ safe_free (query_string); } -ESIVarState::ESIVarState (HttpHeader const *aHeader, char const *uri) - : output (NULL), hdr(hoReply) +ESIVarState::ESIVarState(HttpHeader const *aHeader, char const *uri) : + output(NULL), + hdr(hoReply) { + memset(&flags, 0, sizeof(flags)); + /* TODO: only grab the needed headers */ /* Note that as we pass these through to included requests, we * cannot trim them */