Ghidra is a software reverse engineering (SRE) framework
GP-3783 Check for same VariableGroup before assigning partial Symbol
caheckman17eb87ebf799
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/double.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/double.ccindex 49dd39f4ea..3f923b6505 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/double.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/double.cc@@ -285,7 +285,8 @@ bool SplitVarnode::findWholeSplitToPieces(void)}if (subhi->code() != CPUI_SUBPIECE) return false;if (subhi->getIn(1)->getOffset() != wholesize - hi->getSize()) return false;- whole = subhi->getIn(0);+ Varnode *putativeWhole = subhi->getIn(0);+ if (putativeWhole->getSize() != wholesize) return false;if (!lo->isWritten()) return false;PcodeOp *sublo = lo->getDef();if (sublo->code() == CPUI_COPY) { // Go thru one level of copy, if the piece is addrtied@@ -294,14 +295,11 @@ bool SplitVarnode::findWholeSplitToPieces(void)sublo = otherlo->getDef();}if (sublo->code() != CPUI_SUBPIECE) return false;- Varnode *res = sublo->getIn(0);- if (whole == (Varnode*)0)- whole = res;- else if (whole != res)+ if (putativeWhole != sublo->getIn(0))return false; // Doesn't match between piecesif (sublo->getIn(1)->getOffset() != 0)return false;- if (whole == (Varnode*)0) return false;+ whole = putativeWhole;}if (whole->isWritten()) {diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.ccindex f77817073b..37500c5104 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc@@ -1022,6 +1022,8 @@ void Funcdata::linkProtoPartial(Varnode *vn)if (rootVn == vn) return;HighVariable *rootHigh = rootVn->getHigh();+ if (!rootHigh->isSameGroup(high))+ return;Varnode *nameRep = rootHigh->getNameRepresentative();Symbol *sym = linkSymbol(nameRep);if (sym == (Symbol *)0) return;diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hhindex 19ea60fe1b..2018aca381 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/variable.hh@@ -207,6 +207,7 @@ public:void clearMark(void) const { flags &= ~Varnode::mark; } ///< Clear the mark on this variablebool isMark(void) const { return ((flags&Varnode::mark)!=0); } ///< Return \b true if \b this is markedbool isUnmerged(void) const { return ((highflags&unmerged)!=0); } ///< Return \b true if \b this has merge problems+ bool isSameGroup(const HighVariable *op2) const; ///< Is \b this part of the same VariableGroup as \b op2/// \brief Determine if \b this HighVariable has an associated cover.///@@ -294,5 +295,16 @@ inline const Cover &HighVariable::getCover(void) constreturn piece->getCover();}+/// Test if the two HighVariables should be pieces of the same symbol.+/// \param op2 is the other HighVariable to compare with \b this+/// \return \b true if they share the same underlying VariableGroup+inline bool HighVariable::isSameGroup(const HighVariable *op2) const++{+ if (piece == (VariablePiece *)0 || op2->piece == (VariablePiece *)0)+ return false;+ return piece->getGroup() == op2->piece->getGroup();+}+} // End namespace ghidra#endif