diff options
author | Oxore <oxore@protonmail.com> | 2023-05-15 09:33:10 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2023-05-15 09:33:10 +0300 |
commit | c9d192b63f4866b55623388f3ed53bb68eb2b05c (patch) | |
tree | 3cf2c7445a8172a6d09ed3988b5bfc6c3c25c529 /main.cpp | |
parent | 5a58717212b3385a43350b6583ddac02b090f856 (diff) |
Add trace data sanity checks
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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); |