diff --git a/libclamav/c++/ClamBCRTChecks.cpp b/libclamav/c++/ClamBCRTChecks.cpp index 697a937d9..b39d83045 100644 --- a/libclamav/c++/ClamBCRTChecks.cpp +++ b/libclamav/c++/ClamBCRTChecks.cpp @@ -546,24 +546,38 @@ namespace { LHS = SE->getNoopOrZeroExtend(LHS, LTy); RHS = SE->getNoopOrZeroExtend(RHS, LTy); } - bool checkCondition(CallInst *CI, Instruction *I) + bool checkCond(Instruction *ICI, Instruction *I, bool equal) + { + for (Value::use_iterator JU=ICI->use_begin(),JUE=ICI->use_end(); + JU != JUE; ++JU) { + if (BranchInst *BI = dyn_cast(JU)) { + if (!BI->isConditional()) + continue; + BasicBlock *S = BI->getSuccessor(equal); + if (DT->dominates(S, I->getParent())) + return true; + } + if (BinaryOperator *BI = dyn_cast(JU)) { + if (BI->getOpcode() == Instruction::Or && + checkCond(BI, I, equal)) + return true; + if (BI->getOpcode() == Instruction::And && + checkCond(BI, I, !equal)) + return true; + } + } + return false; + } + + bool checkCondition(Instruction *CI, Instruction *I) { for (Value::use_iterator U=CI->use_begin(),UE=CI->use_end(); U != UE; ++U) { if (ICmpInst *ICI = dyn_cast(U)) { if (ICI->getOperand(0)->stripPointerCasts() == CI && isa(ICI->getOperand(1))) { - for (Value::use_iterator JU=ICI->use_begin(),JUE=ICI->use_end(); - JU != JUE; ++JU) { - if (BranchInst *BI = dyn_cast(JU)) { - if (!BI->isConditional()) - continue; - BasicBlock *S = BI->getSuccessor(ICI->getPredicate() == - ICmpInst::ICMP_EQ); - if (DT->dominates(S, I->getParent())) - return true; - } - } + if (checkCond(ICI, I, ICI->getPredicate() == ICmpInst::ICMP_EQ)) + return true; } } }