From 6a62309459e36d59e4cfe14885fa3ed807841c62 Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Thu, 17 Nov 2016 14:07:54 +0800 Subject: MdePkg BaseLib: API PathRemoveLastItem not handle root paths properly https://bugzilla.tianocore.org/show_bug.cgi?id=239 When the input path for API PathRemoveLastItem() is a root path like 'fs0:\', the API will return TRUE (indicating a directory or file was removed from the path) and modifies the path to 'fs0:'. In fact, there's no directory or file removed in the above case. This commit adds additional check to resolve this issue and modifies the API's description to make it more straightforward. Cc: Ruiyu Ni Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Ruiyu Ni --- MdePkg/Library/BaseLib/FilePaths.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'MdePkg/Library/BaseLib/FilePaths.c') diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c index 183b3234d3..29a84ea902 100644 --- a/MdePkg/Library/BaseLib/FilePaths.c +++ b/MdePkg/Library/BaseLib/FilePaths.c @@ -14,9 +14,8 @@ #include /** - Removes the last directory or file entry in a path by changing the last - L'\' to a CHAR_NULL. For a path which is like L"fs0:startup.nsh", - it's converted to L"fs0:". + Removes the last directory or file entry in a path. For a path which is + like L"fs0:startup.nsh", it's converted to L"fs0:". @param[in,out] Path A pointer to the path to modify. @@ -38,7 +37,9 @@ PathRemoveLastItem( ; Walker != NULL && *Walker != CHAR_NULL ; Walker++ ){ - if ((*Walker == L'\\' || *Walker == L':') && *(Walker + 1) != CHAR_NULL) { + if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) { + LastSlash = Walker+1; + } else if (*Walker == L':' && *(Walker + 1) != L'\\' && *(Walker + 1) != CHAR_NULL) { LastSlash = Walker+1; } } -- cgit v1.2.3