From eabff49a6ab277d128740c001b3db93437062e6d Mon Sep 17 00:00:00 2001 From: Ben Payne Date: Wed, 4 Mar 2015 15:46:07 -0500 Subject: [PATCH] Fix buffer underrun found with address sanitizer When subpath is the empty string, the code was reading from subPath[-1] --- Engine/source/platformWin32/winFileio.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Engine/source/platformWin32/winFileio.cpp b/Engine/source/platformWin32/winFileio.cpp index 36900cd15..0aeab392d 100644 --- a/Engine/source/platformWin32/winFileio.cpp +++ b/Engine/source/platformWin32/winFileio.cpp @@ -1306,8 +1306,10 @@ static bool recurseDumpDirectories(const char *basePath, const char *subPath, Ve // Compose our search string - Format : ([path]/[subpath]/*) //----------------------------------------------------------------------------- - char trail = basePath[ dStrlen(basePath) - 1 ]; - char subTrail = subPath ? subPath[ dStrlen(subPath) - 1 ] : '\0'; + dsize_t trLen = basePath ? dStrlen(basePath) : 0; + dsize_t subtrLen = subPath ? dStrlen(subPath) : 0; + char trail = trLen > 0 ? basePath[ trLen - 1 ] : '\0'; + char subTrail = subtrLen > 0 ? subPath[ subtrLen - 1 ] : '\0'; if( trail == '/' ) {