From 0b5e0745917d065b30fd87fc3abb3e061634ee87 Mon Sep 17 00:00:00 2001 From: AntonioND Date: Sun, 22 Jan 2017 22:56:47 +0000 Subject: [PATCH 1/2] Output error messages for command line includes The code that adds an include path to the array of paths doesn't check the lenght of the path (which can cause overflows because of strcpy). It doesn't check if the max number of paths has been reached, either. This patch adds error messages for such cases, giving the user more information than before and crashing the assembly instead of continuing and failing when it can't find a file to include. --- src/asm/fstack.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 56fc46d0..27dde51b 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -179,6 +179,16 @@ fstk_Dump(void) void fstk_AddIncludePath(char *s) { + if (NextIncPath == MAXINCPATHS) { + fatalerror("Too many include directories passed from command line"); + return; + } + + if (strlen(s) > _MAX_PATH) { + fatalerror("Include path too long '%s'",s); + return; + } + strcpy(IncludePaths[NextIncPath++], s); } From a91187d8dc823677dc0d1edab56d31e3eca14aeb Mon Sep 17 00:00:00 2001 From: AntonioND Date: Sun, 22 Jan 2017 23:08:00 +0000 Subject: [PATCH 2/2] Increase number of include paths through CLI Increase number of include paths that can be passed through the command line interface. The previous number, 16, is only good enough for small projects. 128 is still an arbitrary number, but it is harder to reach. --- include/asm/asm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/asm/asm.h b/include/asm/asm.h index 1f70f6f7..609de1c0 100644 --- a/include/asm/asm.h +++ b/include/asm/asm.h @@ -30,6 +30,6 @@ extern struct sSymbol *pPCSymbol; extern bool oDontExpandStrings; #define MAXMACROARGS 256 -#define MAXINCPATHS 16 +#define MAXINCPATHS 128 #endif /* // ASM_H */