From c9d192b63f4866b55623388f3ed53bb68eb2b05c Mon Sep 17 00:00:00 2001 From: Oxore Date: Mon, 15 May 2023 09:33:10 +0300 Subject: Add trace data sanity checks --- main.cpp | 10 ++++++++-- 1 file 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(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); -- cgit v1.2.3