From d0398c8a835c82d168b189274a2defaf99e096fe Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Thu, 24 Dec 2020 23:24:41 -0800 Subject: [PATCH] Common/FileSystem: Fix canonicalization of paths beginning with `./` If we don't skip past the following separator when the destination is empty, then `./file` gets canonicalized as `/file`. Also, consider the case where we end up with an empty string (for example, from `foo/..`). Canonicalize this as `.`. --- src/common/file_system.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index e3da145c8..53445e00b 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -75,6 +75,9 @@ void CanonicalizePath(char* Destination, u32 cbDestination, const char* Path, bo // remove the previous \, if we have one trailing the dot it'll append it anyway if (destinationLength > 0) Destination[--destinationLength] = '\0'; + // if there was no previous \, skip past the next one + else if (nextCh != '\0') + i++; continue; } @@ -126,6 +129,10 @@ void CanonicalizePath(char* Destination, u32 cbDestination, const char* Path, bo i++; } + // if we end up with the empty string, return '.' + if (destinationLength == 0) + Destination[destinationLength++] = '.'; + // ensure nullptr termination if (destinationLength < cbDestination) Destination[destinationLength] = '\0';