1- From 0e437cb96249306d17f26ff6614871ecd9b37359 Mon Sep 17 00:00:00 2001
2- From: "github-actions[bot]"
3- <41898282+github-actions[bot]@users.noreply.github.com>
4- Date: Wed, 2 Aug 2023 23:19:42 +1000
5- Subject: [PATCH 1/2] Fix UBSAN errors in decompiler
1+ From 6c36965500d26d5a35dfbc91725956ae1d51e394 Mon Sep 17 00:00:00 2001
2+ From: Alex Cameron <
[email protected] >
3+ Date: Mon, 5 Jun 2023 16:45:04 +1200
4+ Subject: [PATCH 1/5] Fix UBSAN errors in decompiler
65
76---
87 .../Decompiler/src/decompile/cpp/fspec.cc | 8 ++++++--
@@ -14,16 +13,15 @@ Subject: [PATCH 1/2] Fix UBSAN errors in decompiler
1413 .../Decompiler/src/decompile/cpp/semantics.cc | 2 ++
1514 .../Decompiler/src/decompile/cpp/semantics.hh | 2 +-
1615 .../src/decompile/cpp/slgh_compile.cc | 2 +-
17- .../Decompiler/src/decompile/cpp/slghsymbol.cc | 2 +-
1816 .../Decompiler/src/decompile/cpp/type.cc | 2 +-
1917 .../src/decompile/unittests/testfloatemu.cc | 2 +-
20- 12 files changed, 57 insertions(+), 21 deletions(-)
18+ 11 files changed, 56 insertions(+), 20 deletions(-)
2119
2220diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
23- index 8380d3cd..a18d5007 100644
21+ index dc96f0c19..3482cf17c 100644
2422--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
2523+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
26- @@ -2661 ,8 +2661 ,12 @@ void ProtoModelMerged::decode(Decoder &decoder)
24+ @@ -2727 ,8 +2727 ,12 @@ void ProtoModelMerged::decode(Decoder &decoder)
2725 modellist.push_back(mymodel);
2826 }
2927 decoder.closeElement(elemId);
@@ -39,7 +37,7 @@ index 8380d3cd..a18d5007 100644
3937
4038 void ParameterBasic::setTypeLock(bool val)
4139diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
42- index f7781707..283d81c3 100644
40+ index fc094ee96..1f7e53ebe 100644
4341--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
4442+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc
4543@@ -503,7 +503,13 @@ void Funcdata::setHighLevel(void)
@@ -58,10 +56,10 @@ index f7781707..283d81c3 100644
5856 uint4 vnFlags = vn->getFlags() & (Varnode::directwrite|Varnode::addrforce);
5957
6058diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
61- index 0e3decc8..403ec35a 100644
59+ index 921335173..46cdc39f3 100644
6260--- a/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
6361+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/op.cc
64- @@ -672 ,7 +672 ,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
62+ @@ -666 ,7 +666 ,11 @@ uintb PcodeOp::getNZMaskLocal(bool cliploop) const
6563 break;
6664 case CPUI_PIECE:
6765 resmask = getIn(0)->getNZMask();
@@ -75,10 +73,10 @@ index 0e3decc8..403ec35a 100644
7573 break;
7674 case CPUI_INT_MULT:
7775diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
78- index fcd75cc7..ed0e005a 100644
76+ index aebcfd910..6c47e6eb1 100644
7977--- a/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
8078+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opbehavior.cc
81- @@ -750 ,7 +750 ,13 @@ uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb i
79+ @@ -746 ,7 +746 ,13 @@ uintb OpBehaviorPiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb i
8280 uintb OpBehaviorSubpiece::evaluateBinary(int4 sizeout,int4 sizein,uintb in1,uintb in2) const
8381
8482 {
@@ -94,7 +92,7 @@ index fcd75cc7..ed0e005a 100644
9492 }
9593
9694diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
97- index ca9d71ab..85d4dd28 100644
95+ index ca9d71ab9..85d4dd281 100644
9896--- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
9997+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
10098@@ -621,8 +621,10 @@ vector<OpTpl *> *PcodeCompile::assignBitRange(VarnodeTpl *vn,uint4 bitoffset,uin
@@ -137,7 +135,7 @@ index ca9d71ab..85d4dd28 100644
137135 return res;
138136 }
139137diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
140- index 4851365d..d069d1c9 100644
138+ index 3703c8ef5..ac6e21c00 100644
141139--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
142140+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ruleaction.cc
143141@@ -976,7 +976,12 @@ int4 RulePullsubIndirect::applyOp(PcodeOp *op,Funcdata &data)
@@ -154,7 +152,7 @@ index 4851365d..d069d1c9 100644
154152 consume = ~consume;
155153 if ((consume & indir->getIn(0)->getConsume())!=0) return 0;
156154
157- @@ -6782 ,8 +6787 ,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
155+ @@ -6803 ,8 +6808 ,9 @@ int4 RulePtrsubCharConstant::applyOp(PcodeOp *op,Funcdata &data)
158156 Varnode *sb = op->getIn(0);
159157 Datatype *sbType = sb->getTypeReadFacing(op);
160158 if (sbType->getMetatype() != TYPE_PTR) return 0;
@@ -166,7 +164,7 @@ index 4851365d..d069d1c9 100644
166164 Varnode *vn1 = op->getIn(1);
167165 if (!vn1->isConstant()) return 0;
168166 Varnode *outvn = op->getOut();
169- @@ -8593 ,7 +8599 ,11 @@ int4 RuleSubvarSubpiece::applyOp(PcodeOp *op,Funcdata &data)
167+ @@ -8616 ,7 +8622 ,11 @@ int4 RuleSubvarSubpiece::applyOp(PcodeOp *op,Funcdata &data)
170168 Varnode *outvn = op->getOut();
171169 int4 flowsize = outvn->getSize();
172170 uintb mask = calc_mask( flowsize );
@@ -180,7 +178,7 @@ index 4851365d..d069d1c9 100644
180178 if (!aggressive) {
181179 if ((vn->getConsume() & mask) != vn->getConsume()) return 0;
182180diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
183- index 2e3531ea..42482be7 100644
181+ index cd9b9835b..8a4616c3b 100644
184182--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
185183+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
186184@@ -22,6 +22,7 @@ ConstTpl::ConstTpl(const_type tp)
@@ -200,23 +198,23 @@ index 2e3531ea..42482be7 100644
200198
201199 bool ConstTpl::isConstSpace(void) const
202200diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
203- index 8e283dca..652600c1 100644
201+ index e0b069959..9117a45c7 100644
204202--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
205203+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
206- @@ -48 ,7 +48 ,7 @@ private:
207- static void printHandleSelector(ostream &s,v_field val) ;
208- static v_field readHandleSelector(const string &name);
204+ @@ -47 ,7 +47 ,7 @@ class ConstTpl {
205+ uintb value_real ;
206+ v_field select; // Which part of handle to use as constant
209207 public:
210208- ConstTpl(void) { type = real; value_real = 0; }
211209+ ConstTpl(void) { type = real; value_real = 0; select = v_space; }
212210 ConstTpl(const ConstTpl &op2) {
213211 type=op2.type; value=op2.value; value_real=op2.value_real; select=op2.select; }
214212 ConstTpl(const_type tp,uintb val);
215213diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
216- index b40f7438..3c37958d 100644
214+ index c060053bf..c9004023c 100644
217215--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
218216+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
219- @@ -2163 ,8 +2163 ,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
217+ @@ -2164 ,8 +2164 ,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
220218 ostringstream msg;
221219 SymbolTree::const_iterator iter;
222220 for(iter=scope->begin();iter!=scope->end();++iter) {
@@ -226,24 +224,11 @@ index b40f7438..3c37958d 100644
226224 if (sym->getRefCount() == 0)
227225 msg << " Label <" << sym->getName() << "> was placed but not used" << endl;
228226 else if (!sym->isPlaced())
229- diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
230- index b308e1b7..af2982ae 100644
231- --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
232- +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc
233- @@ -2569,7 +2569,7 @@ void ContextOp::restoreXml(const Element *el,SleighBase *trans)
234- const List &list(el->getChildren());
235- List::const_iterator iter;
236- iter = list.begin();
237- - patexp = (PatternValue *)PatternExpression::restoreExpression(*iter,trans);
238- + patexp = PatternExpression::restoreExpression(*iter,trans);
239- patexp->layClaim();
240- }
241-
242227diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
243- index 30faf0b6..e76a0619 100644
228+ index e6292e138..bd31b7470 100644
244229--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
245230+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
246- @@ -3359 ,8 +3359 ,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
231+ @@ -3561 ,8 +3561 ,8 @@ void TypeFactory::recalcPointerSubmeta(Datatype *base,sub_metatype sub)
247232 top.submeta = sub; // Search on the incorrect submeta
248233 iter = tree.lower_bound(&top);
249234 while(iter != tree.end()) {
@@ -254,7 +239,7 @@ index 30faf0b6..e76a0619 100644
254239 ++iter;
255240 if (ptr->submeta == sub) {
256241diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
257- index c35bde87..061e5367 100644
242+ index c35bde877..061e53677 100644
258243--- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
259244+++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc
260245@@ -346,7 +346,7 @@ TEST(float_opTrunc_to_int) {
@@ -267,5 +252,5 @@ index c35bde87..061e5367 100644
267252 uintb true_result = ((uintb)(int32_t)f) & 0xffffffff;
268253 uintb encoding = format.getEncoding(f);
269254- -
270- 2.39.2 (Apple Git-143)
255+ 2.44.0
271256
0 commit comments