From 055fafe1ce85013f1c868690ad06454a405c6af2 Mon Sep 17 00:00:00 2001 From: Huajing Li Date: Mon, 28 Aug 2017 11:47:52 +0800 Subject: [PATCH] ShellPkg: Fix bug that fails to change CWD after "map -r". When "map -r" runs, the mapping list is re-created but gShellCurMapping still points to the old mapping list which is already destroyed. The patch updates the gShellCurMapping to point to the correct location in the new mapping list. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Huajing Li Reviewed-by: Ruiyu Ni Reviewed-by Jaben Carsey --- .../UefiShellCommandLib/UefiShellCommandLib.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index b9158d1243..c7984f11b2 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1268,7 +1268,14 @@ ShellCommandCreateInitialMappingsAndPaths( CHAR16 *NewConsistName; EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable; SHELL_MAP_LIST *MapListNode; + CONST CHAR16 *CurDir; + CHAR16 *SplitCurDir; + CHAR16 *MapName; + SHELL_MAP_LIST *MapListItem; + SplitCurDir = NULL; + MapName = NULL; + MapListItem = NULL; HandleList = NULL; // @@ -1354,6 +1361,33 @@ ShellCommandCreateInitialMappingsAndPaths( SHELL_FREE_NON_NULL(DevicePathList); HandleList = NULL; + + // + //gShellCurMapping point to node of current file system in the gShellMapList. When reset all mappings, + //all nodes in the gShellMapList will be free. Then gShellCurMapping will be a dangling pointer, So, + //after created new mappings, we should reset the gShellCurMapping pointer back to node of current file system. + // + if (gShellCurMapping != NULL) { + gShellCurMapping = NULL; + CurDir = gEfiShellProtocol->GetEnv(L"cwd"); + if (CurDir != NULL) { + MapName = AllocateCopyPool (StrSize(CurDir), CurDir); + if (MapName == NULL) { + return EFI_OUT_OF_RESOURCES; + } + SplitCurDir = StrStr (MapName, L":"); + if (SplitCurDir == NULL) { + SHELL_FREE_NON_NULL (MapName); + return EFI_UNSUPPORTED; + } + *(SplitCurDir + 1) = CHAR_NULL; + MapListItem = ShellCommandFindMapItem (MapName); + if (MapListItem != NULL) { + gShellCurMapping = MapListItem; + } + SHELL_FREE_NON_NULL (MapName); + } + } } else { Count = (UINTN)-1; }