From 0b5e0745917d065b30fd87fc3abb3e061634ee87 Mon Sep 17 00:00:00 2001 From: AntonioND Date: Sun, 22 Jan 2017 22:56:47 +0000 Subject: [PATCH] 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); }