Przeglądaj źródła

Fix buffer underrun found with address sanitizer

When subpath is the empty string, the code was reading from subPath[-1]
Ben Payne 10 lat temu
rodzic
commit
eabff49a6a
1 zmienionych plików z 4 dodań i 2 usunięć
  1. 4 2
      Engine/source/platformWin32/winFileio.cpp

+ 4 - 2
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 == '/' )
    {