Add address offset parsing patch (#119)

* Fixes tests on Windows

* Update README for full Windows support
This commit is contained in:
Alex Cameron
2022-08-03 23:15:56 +10:00
committed by GitHub
parent 2aa04f941e
commit ff84f3c8de
4 changed files with 77 additions and 1 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ This repository provides a CMake-based build project for SLEIGH so that it can b
| ---- | ------- |
| Linux | Yes |
| macOS | Yes |
| Windows | Not yet |
| Windows | Yes |
## Dependencies and Prerequisites
@@ -0,0 +1,37 @@
From 773dda85b84a03c8795e27f1df87e6024bdb208a Mon Sep 17 00:00:00 2001
From: Alex Cameron <asc@tetsuo.sh>
Date: Wed, 3 Aug 2022 20:01:18 +1000
Subject: [PATCH] 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 c51e58560..c5cc7541d 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
@@ -16,6 +16,8 @@
#include "space.hh"
#include "translate.hh"
+#include <climits>
+
AttributeId ATTRIB_BASE = AttributeId("base",89);
AttributeId ATTRIB_DEADCODEDELAY = AttributeId("deadcodedelay",90);
AttributeId ATTRIB_DELAY = AttributeId("delay", 91);
@@ -268,7 +270,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
}
}
catch(LowlevelError &err) { // Name doesn't exist
- offset = strtoul(s.c_str(),&tmpdata,0);
+ offset = strtoull(s.c_str(),&tmpdata,0);
+ if (offset == ULLONG_MAX) {
+ throw LowlevelError("Offset outside of valid range");
+ }
offset = addressToByte(offset,wordsize);
enddata = (const char *) tmpdata;
if (enddata - s.c_str() == s.size()) { // If no size or offset override
--
2.32.1 (Apple Git-133)
@@ -0,0 +1,37 @@
From b719ae7f3716b303ec0c3d8c79e7d55c7e7cbfdf Mon Sep 17 00:00:00 2001
From: Alex Cameron <asc@tetsuo.sh>
Date: Wed, 3 Aug 2022 20:39:30 +1000
Subject: [PATCH] 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 5f07edf8e..b86c9beae 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
@@ -16,6 +16,8 @@
#include "space.hh"
#include "translate.hh"
+#include <climits>
+
/// Calculate \e highest based on \e addressSize, and \e wordsize.
/// This also calculates the default pointerLowerBound
void AddrSpace::calcScaleMask(void)
@@ -260,7 +262,10 @@ uintb AddrSpace::read(const string &s,int4 &size) const
}
}
catch(LowlevelError &err) { // Name doesn't exist
- offset = strtoul(s.c_str(),&tmpdata,0);
+ offset = strtoull(s.c_str(),&tmpdata,0);
+ if (offset == ULLONG_MAX) {
+ throw LowlevelError("Offset outside of valid range");
+ }
offset = addressToByte(offset,wordsize);
enddata = (const char *) tmpdata;
if (enddata - s.c_str() == s.size()) { // If no size or offset override
--
2.32.1 (Apple Git-133)
+2
View File
@@ -21,6 +21,7 @@ set(ghidra_patches
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0001-Small-improvements-to-C-decompiler-testing-from-CLI.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0002-Add-include-guards-to-decompiler-C-headers.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0003-Fix-UBSAN-errors-in-decompiler.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/stable/0004-Use-stroull-instead-of-stroul-to-parse-address-offse.patch"
)
# Ghidra pinned commits used for pinning last known working HEAD commit
@@ -38,6 +39,7 @@ if("${sleigh_RELEASE_TYPE}" STREQUAL "HEAD")
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0002-Initialize-ID-lookup-tables-to-fix-sleighexample.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0003-Add-include-guards-to-decompiler-C-headers.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0004-Fix-UBSAN-errors-in-decompiler.patch"
"${CMAKE_CURRENT_SOURCE_DIR}/patches/HEAD/0005-Use-stroull-instead-of-stroul-to-parse-address-offse.patch"
)
string(SUBSTRING "${ghidra_git_tag}" 0 7 ghidra_short_commit)
else()