summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-05-15 09:33:10 +0300
committerOxore <oxore@protonmail.com>2023-05-15 09:33:10 +0300
commitc9d192b63f4866b55623388f3ed53bb68eb2b05c (patch)
tree3cf2c7445a8172a6d09ed3988b5bfc6c3c25c529
parent5a58717212b3385a43350b6583ddac02b090f856 (diff)
Add trace data sanity checks
-rw-r--r--main.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/main.cpp b/main.cpp
index a1f2214..122e556 100644
--- a/main.cpp
+++ b/main.cpp
@@ -220,9 +220,15 @@ static void ParseTraceData(DisasmMap &disasm_map, const DataBuffer &trace_data)
char *endptr = startptr;
const long offset = strtol(startptr, &endptr, 10);
if ((offset == LONG_MAX || offset == LONG_MIN) && errno == ERANGE) {
- // Error, just skip
+ // Parsing error, just skip
} else if (startptr == endptr) {
- // Error, just skip
+ // Parsing error, just skip
+ } else if (offset % 2) {
+ fprintf(stderr, "Error: Uneven PC values are not supported (got PC=0x%08lx), exiting\n", offset);
+ exit(1);
+ } else if (static_cast<unsigned long>(offset) > kRomSizeBytes) {
+ fprintf(stderr, "Error: PC values > 4MiB are not supported (got PC=0x%08lx), exiting\n", offset);
+ exit(1);
} else {
// Valid value
disasm_map.InsertTracedNode(offset, TracedNodeType::kInstruction);