From e50bcaa2725a3538433455fed617f198fed7b47d Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 13 Jan 2020 16:21:13 +0100 Subject: [PATCH] Enforce trailing slash in include paths Fixes rednex#456 --- src/asm/fstack.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/asm/fstack.c b/src/asm/fstack.c index 28a60943..9a19df73 100644 --- a/src/asm/fstack.c +++ b/src/asm/fstack.c @@ -316,7 +316,11 @@ void fstk_AddIncludePath(char *s) if (NextIncPath == MAXINCPATHS) fatalerror("Too many include directories passed from command line"); - if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, "%s", + // Find last occurrence of slash; is it at the end of the string? + char const *lastSlash = strrchr(s, '/'); + char const *pattern = lastSlash && *(lastSlash + 1) == 0 ? "%s" : "%s/"; + + if (snprintf(IncludePaths[NextIncPath++], _MAX_PATH, pattern, s) >= _MAX_PATH) fatalerror("Include path too long '%s'", s); }