Ghidra is a software reverse engineering (SRE) framework
GP-2654 Varnodes overlapping multiple structure fields can reconcile
caheckman35cfd02d8773
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.ccindex fd746de500..f40f3dd669 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc@@ -214,7 +214,6 @@ int main(int argc,char **argv)if (initscript != (const char *)0) {try {- status->setErrorIsDone(true);status->pushScript(initscript,"init> ");} catch(IfaceParseError &err) {*status->optr << err.explain << endl;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.ccindex de5098430c..a4c6b71fc7 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc@@ -4661,6 +4661,8 @@ void ActionInferTypes::propagateRef(Funcdata &data,Varnode *vn,const Address &ad++iter;if (curvn->isAnnotation()) continue;if ((!curvn->isWritten())&&curvn->hasNoDescend()) continue;+ if (curvn->isTypeLock()) continue;+ if (curvn->getSymbolEntry() != (SymbolEntry *)0) continue;uintb curoff = curvn->getOffset() - off;int4 cursize = curvn->getSize();if (curoff + cursize > ct->getSize()) continue;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.ccindex c404d9f125..8ac61f8892 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc@@ -162,6 +162,7 @@ void IfaceStatus::pushScript(istream *iptr,const string &newprompt)if (errorisdone)flags |= 1;flagstack.push_back(flags);+ errorisdone = true; // Abort on first exception in a scriptprompt = newprompt;}diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.ccindex f4eb6dc474..fd42fe4976 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varmap.cc@@ -48,8 +48,21 @@ bool RangeHint::reconcile(const RangeHint *b) constif (sub == (Datatype *)0) return false;if (umod != 0) return false;- if (sub->getSize() < b->type->getSize()) return false;- return true;+ if (sub->getSize() == b->type->getSize()) return true;+ if ((b->flags & Varnode::typelock)!=0) return false;+ // If we reach here, component sizes do not match+ // Check for data-types we want to protect more+ type_metatype meta = a->type->getMetatype();+ if (meta != TYPE_STRUCT && meta != TYPE_UNION) {+ if (meta != TYPE_ARRAY || ((TypeArray *)(a->type))->getBase()->getMetatype() == TYPE_UNKNOWN)+ return false;+ }+ // For structures, unions, and arrays, test if b looks like a partial data-type+ meta = b->type->getMetatype();+ if (meta == TYPE_UNKNOWN || meta == TYPE_INT || meta == TYPE_UINT) {+ return true;+ }+ return false;}/// \brief Return \b true if \b this or the given range contains the other.