From 3112ed67f92d65863d736fafb7d62b0428acb11a Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 30 Aug 2020 17:05:48 +0200 Subject: emul: find illegal address references to opcodes (avoid endless loops) --- ecomp-c/emul.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ecomp-c/emul.c b/ecomp-c/emul.c index c67ca49..e4234f9 100644 --- a/ecomp-c/emul.c +++ b/ecomp-c/emul.c @@ -304,6 +304,7 @@ int main( int argc, char *argv[] ) uint64_t address = CODE_START; bool terminate = false; + bool notfound = false; int iteration = 1; printf( "Single step execution:\n" ); @@ -316,7 +317,15 @@ int main( int argc, char *argv[] ) while( instrs_map[n+1] != address ) { n += 2; if( n >= 2 * N ) { - n = 0; + if( !notfound ) { + n = 0; + notfound = true; + } else { + fprintf( stderr, "ERROR: address %X not found in hashmap\n", (unsigned int)address ); + cs_close( &cs ); + uc_close( uc ); + exit( EXIT_FAILURE ); + } } } n = instrs_map[n]; -- cgit v1.2.3-54-g00ecf