Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/patches/stable/0001-Fix-UBSAN-errors-in-decompiler.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0a73bf28abee06ccc349db45cc220d221fac875e Mon Sep 17 00:00:00 2001
From eebf63ed22e5c2363e41f997c666ae7855b44e5b Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Mon, 12 Aug 2024 12:02:35 -0400
Subject: [PATCH 1/8] Fix UBSAN errors in decompiler
Subject: [PATCH 1/9] Fix UBSAN errors in decompiler

Co-authored-by: Alex Cameron <asc@tetsuo.sh>
---
Expand All @@ -13,10 +13,10 @@ Co-authored-by: Alex Cameron <asc@tetsuo.sh>
5 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
index a67a3de849..37ba4930e6 100644
index de3ec1af20..0274060de1 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/pcodecompile.cc
@@ -618,8 +618,10 @@ vector<OpTpl *> *PcodeCompile::assignBitRange(VarnodeTpl *vn,uint4 bitoffset,uin
@@ -772,8 +772,10 @@ vector<OpTpl *> *PcodeCompile::assignBitRange(VarnodeTpl *vn,uint4 bitoffset,uin
uint4 smallsize = (numbits+7)/8; // Size of input (output of rhs)
bool shiftneeded = (bitoffset != 0);
bool zextneeded = true;
Expand All @@ -29,7 +29,7 @@ index a67a3de849..37ba4930e6 100644

if (vn->getSize().getType()==ConstTpl::real) {
// If we know the size of the bitranged varnode, we can
@@ -723,9 +725,6 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
@@ -884,9 +886,6 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
}
}

Expand All @@ -39,7 +39,7 @@ index a67a3de849..37ba4930e6 100644
if (truncneeded && ((bitoffset % 8)==0)) {
truncshift = bitoffset/8;
bitoffset = 0;
@@ -748,8 +747,13 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
@@ -909,8 +908,13 @@ ExprTree *PcodeCompile::createBitRange(SpecificSymbol *sym,uint4 bitoffset,uint4
appendOp(CPUI_INT_RIGHT,res,bitoffset,4);
if (truncneeded)
appendOp(CPUI_SUBPIECE,res,truncshift,4);
Expand All @@ -56,18 +56,18 @@ index a67a3de849..37ba4930e6 100644
return res;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
index 7b06da8e0b..032c6d69e5 100644
index c729073918..9ec58e18d3 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.cc
@@ -22,6 +22,7 @@ ConstTpl::ConstTpl(const_type tp)
@@ -23,6 +23,7 @@ ConstTpl::ConstTpl(const_type tp)

{ // Constructor for relative jump constants and uniques
{
type = tp;
+ select = v_space;
}

ConstTpl::ConstTpl(const_type tp,uintb val)
@@ -56,6 +57,7 @@ ConstTpl::ConstTpl(AddrSpace *sid)
/// \param tp is constant type: either \b real or \b j_relative
@@ -67,6 +68,7 @@ ConstTpl::ConstTpl(AddrSpace *sid)
{
type = spaceid;
value.spaceid = sid;
Expand All @@ -76,23 +76,23 @@ index 7b06da8e0b..032c6d69e5 100644

bool ConstTpl::isConstSpace(void) const
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
index 2a768a7bef..c33a4f7d3c 100644
index b878b840e6..12df5e548c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/semantics.hh
@@ -47,7 +47,7 @@ class ConstTpl {
uintb value_real;
v_field select; // Which part of handle to use as constant
@@ -83,7 +83,7 @@ class ConstTpl {
uintb value_real; ///< An immediate constant value or other constant offset a ConstTpl represents
v_field select; ///< Assuming ConstTpl is a \b handle, the part of the \b handle to use as constant
public:
- ConstTpl(void) { type = real; value_real = 0; }
+ ConstTpl(void) { type = real; value_real = 0; select = v_space; }
- ConstTpl(void) { type = real; value_real = 0; } ///< Construct a zero constant
+ ConstTpl(void) { type = real; value_real = 0; select = v_space; } ///< Construct a zero constant
ConstTpl(const ConstTpl &op2) {
type=op2.type; value=op2.value; value_real=op2.value_real; select=op2.select; }
ConstTpl(const_type tp,uintb val);
type=op2.type; value=op2.value; value_real=op2.value_real; select=op2.select; } ///< Copy constructor
ConstTpl(const_type tp,uintb val); ///< Constructor for real constants or relative offsets
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
index 02866ccd72..aa907a0e7a 100644
index e84eeca8c2..070c8117b9 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.cc
@@ -2354,8 +2354,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
@@ -2337,8 +2337,8 @@ string SleighCompile::checkSymbols(SymbolScope *scope)
ostringstream msg;
SymbolTree::const_iterator iter;
for(iter=scope->begin();iter!=scope->end();++iter) {
Expand All @@ -116,5 +116,5 @@ index 2571f55f1a..fe40e22b1b 100644
uintb true_result = ((uintb)(int32_t)f) & 0xffffffff;
uintb encoding = format.getEncoding(f);
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
From 6bd6e00f3518915a59d79f4757f2829b745c6476 Mon Sep 17 00:00:00 2001
From 8a93034bbd5d2554b30258e851e7db6499511718 Mon Sep 17 00:00:00 2001
From: Alex Cameron <asc@tetsuo.sh>
Date: Wed, 3 Aug 2022 20:01:18 +1000
Subject: [PATCH 2/8] Use `stroull` instead of `stroul` to parse address
Subject: [PATCH 2/9] Use `stroull` instead of `stroul` to parse address
offsets

---
Ghidra/Features/Decompiler/src/decompile/cpp/space.cc | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
index dbaa2e775f..72927bf379 100644
index 6a8cc94d63..4f2dd6a518 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
@@ -16,6 +16,8 @@
Expand All @@ -21,7 +21,7 @@ index dbaa2e775f..72927bf379 100644
namespace ghidra {

AttributeId ATTRIB_BASE = AttributeId("base",89);
@@ -277,7 +279,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
@@ -290,7 +292,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
}
}
catch(LowlevelError &err) { // Name doesn't exist
Expand All @@ -34,5 +34,5 @@ index dbaa2e775f..72927bf379 100644
enddata = (const char *) tmpdata;
if (enddata - s.c_str() == s.size()) { // If no size or offset override
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 4bab9365b72ee993c48e225f26f438cb6036007c Mon Sep 17 00:00:00 2001
From b27b806032d2fa6d58e5ed393a29bb2a2f73ee7f Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Tue, 29 Oct 2024 17:51:09 -0400
Subject: [PATCH 3/8] Ignore floating point test due to compilation differences
Subject: [PATCH 3/9] Ignore floating point test due to compilation differences

This test fails on macOS and Windows. I'm unsure whether it's an OS or
compiler issue.
Expand All @@ -24,5 +24,5 @@ index fe40e22b1b..91440e2510 100644
ASSERT_EQUALS(ff.printDecimal(f2, false), "0.33333334");
double f3 = doubleFromRawBits(0x3fd0000000000000);
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 3cef6bbaa78272a8fcef5c319dffb57fc2f9931a Mon Sep 17 00:00:00 2001
From 325ba7f4ce5256982eb3b42c6a8f79ea9d274e42 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Wed, 30 Oct 2024 14:26:57 -0400
Subject: [PATCH 4/8] Allow positive or negative NAN in decompiler floating
Subject: [PATCH 4/9] Allow positive or negative NAN in decompiler floating
point test

At least on Apple Silicon, this test reports positive NAN.
Expand Down Expand Up @@ -33,5 +33,5 @@ index f8108d3d32..1060a3e193 100644
<stringmatch name="Float print #14" min="1" max="1">double7 = 3.1415926535897933e-06;</stringmatch>
</decompilertest>
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From d062191ef46398d7b4ff799feb9890449527f876 Mon Sep 17 00:00:00 2001
From cd369f020012e7dd776e4ff3e1a083d96aa55be2 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.d.kilmer@gmail.com>
Date: Sat, 8 Feb 2025 17:59:57 -0500
Subject: [PATCH 5/8] decompiler: Fix strict weak ordering TypePartialEnum
Subject: [PATCH 5/9] decompiler: Fix strict weak ordering TypePartialEnum

This fixes Windows Debug error encountered in testing where it was
complaining about lack of strict weak ordering.
Expand All @@ -10,10 +10,10 @@ complaining about lack of strict weak ordering.
1 file changed, 1 insertion(+)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
index e8c7f511e2..eb7c88a337 100644
index 6b226036cb..2ff7c69090 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.cc
@@ -2724,6 +2724,7 @@ int4 TypePartialEnum::compareDependency(const Datatype &op) const
@@ -2830,6 +2830,7 @@ int4 TypePartialEnum::compareDependency(const Datatype &op) const

{
if (submeta != op.getSubMeta()) return (submeta < op.getSubMeta()) ? -1 : 1;
Expand All @@ -22,5 +22,5 @@ index e8c7f511e2..eb7c88a337 100644
if (parent != tp->parent) return (parent < tp->parent) ? -1 : 1; // Compare absolute pointers
if (offset != tp->offset) return (offset < tp->offset) ? -1 : 1;
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
From ea9505a0ee94b582704801bad7976495ea0b1be8 Mon Sep 17 00:00:00 2001
From 685f245d0758b270a821ff1865b4506c98e7090b Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 25 Feb 2026 02:29:10 +0000
Subject: [PATCH 6/8] decompiler: Fix strict weak ordering PullRecord
Subject: [PATCH 6/9] decompiler: Fix strict weak ordering PullRecord

When both readOp pointers are null, PullRecord::operator< incorrectly
returns true, violating strict weak ordering (irreflexivity). This is
Expand All @@ -25,5 +25,5 @@ index 5d7d650365..22109c7b9c 100644
return false;
return false;
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
From 12542df689c3dd04fba8de48bc37c7946c258e97 Mon Sep 17 00:00:00 2001
From 43409d7997998eff320e86276cbb6e6b7cb5744f Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 25 Feb 2026 02:43:17 +0000
Subject: [PATCH 7/8] decompiler: Fix strict weak ordering compareFinalOrder
Subject: [PATCH 7/9] decompiler: Fix strict weak ordering compareFinalOrder

FlowBlock::compareFinalOrder returns true when both blocks have index 0,
violating strict weak ordering (irreflexivity). This is caught by libc++
Expand All @@ -12,10 +12,10 @@ debug mode hardening assertions during BlockGraph::orderBlocks sort.
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc
index 615057605d..4fa81f34f4 100644
index 55fc9264ea..c713f0c42f 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc
@@ -709,7 +709,7 @@ string FlowBlock::typeToName(FlowBlock::block_type bt)
@@ -718,7 +718,7 @@ string FlowBlock::typeToName(FlowBlock::block_type bt)
bool FlowBlock::compareFinalOrder(const FlowBlock *bl1,const FlowBlock *bl2)

{
Expand All @@ -25,5 +25,5 @@ index 615057605d..4fa81f34f4 100644
PcodeOp *op1 = bl1->lastOp();
PcodeOp *op2 = bl2->lastOp();
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
From 0a62e2dd4ba2a53ade5a4261efaad4dcea565e69 Mon Sep 17 00:00:00 2001
From dc2e178a34983f06fb55227195239d2451aad81c Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 25 Feb 2026 20:41:10 +0000
Subject: [PATCH 8/8] Fix UBSAN signed left shift errors
Subject: [PATCH 8/9] Fix UBSAN signed left shift errors

Cast signed values to unsigned before left shifting to avoid undefined
behavior when the signed value is negative or when the result cannot be
Expand All @@ -18,10 +18,10 @@ Fixes runtime errors detected by UndefinedBehaviorSanitizer:
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh
index 6fdc9a5478..6fb84c996f 100644
index f2ef7a9ae9..db9493a557 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh
@@ -596,7 +596,7 @@ inline intb sign_extend(intb val,int4 bit)
@@ -601,7 +601,7 @@ inline intb sign_extend(intb val,int4 bit)

{
int4 sa = 8*sizeof(intb) - (bit+1);
Expand Down Expand Up @@ -53,5 +53,5 @@ index a724f3013f..b7ccedeeb2 100644

void LeftShiftExpression::encode(Encoder &encoder) const
--
2.55.0
2.54.0 (Apple Git-157)

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 730b366b9123abfdab4710d7ee1bbc4e3d4ad912 Mon Sep 17 00:00:00 2001
From: Eric Kilmer <eric.kilmer@trailofbits.com>
Date: Tue, 21 Apr 2026 10:32:17 -0400
Subject: [PATCH 9/9] Use std::stoull instead of std::stoul in scan_number for
MSVC

std::stoul returns `unsigned long`, which is 32 bits on MSVC (LLP64) but 64
bits on POSIX LP64. scan_number assigns the result into a `uintb` (uint64_t),
so on Windows any integer literal in a .slaspec file that exceeds 0xFFFFFFFF
throws std::out_of_range, the catch-all returns BADINTEGER, and the sleigh
compiler rejects the spec. Affected specs include 68000/PowerPC/Loongarch/
coldfire/avr32a and others that use 64-bit immediates.

std::stoull returns `unsigned long long` (64 bits on all platforms), matching
the uintb target and the pre-GP-6608 behavior. This mirrors the earlier fix
applied to AddrSpace::read in space.cc.
---
Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc | 2 +-
Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc
index a8545a5f3d..cfae3d6553 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.cc
@@ -1582,7 +1582,7 @@ int4 scan_number(char *numtext,SLEIGHSTYPE *lval,int4 radix,bool signednum)
{
uintb val;
try {
- val = std::stoul(numtext,(size_t *)0,radix);
+ val = std::stoull(numtext,(size_t *)0,radix);
}
catch(...) {
return BADINTEGER;
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l
index 1c25962a45..29db987b61 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghscan.l
@@ -461,7 +461,7 @@ int4 scan_number(char *numtext,SLEIGHSTYPE *lval,int4 radix,bool signednum)
{
uintb val;
try {
- val = std::stoul(numtext,(size_t *)0,radix);
+ val = std::stoull(numtext,(size_t *)0,radix);
}
catch(...) {
return BADINTEGER;
--
2.54.0 (Apple Git-157)

3 changes: 2 additions & 1 deletion src/setup-ghidra-source.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set_property(CACHE sleigh_RELEASE_TYPE PROPERTY STRINGS "stable" "HEAD")
find_package(Git REQUIRED)

# Ghidra pinned stable version commit
set(ghidra_version "12.1.4")
set(ghidra_version "12.2")
set(ghidra_git_tag "Ghidra_${ghidra_version}_build")
set(ghidra_shallow TRUE)

Expand All @@ -47,6 +47,7 @@ set(ghidra_patches
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0006-decompiler-Fix-strict-weak-ordering-PullRecord.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0007-decompiler-Fix-strict-weak-ordering-compareFinalOrde.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0008-Fix-UBSAN-signed-left-shift-errors.patch"
"${CMAKE_CURRENT_LIST_DIR}/patches/stable/0009-Use-std-stoull-instead-of-std-stoul-in-scan_number-f.patch"
)

# Ghidra pinned commits used for pinning last known working HEAD commit
Expand Down
Loading