/** @file\r
Main file for attrib shell level 2 function.\r
\r
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
- Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
} else {\r
CwdSize = StrSize(Directory) + sizeof(CHAR16);\r
Cwd = AllocateZeroPool(CwdSize);\r
- ASSERT(Cwd!=NULL);\r
- StrCpyS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, Directory);\r
- StrCatS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, L"\\");\r
- Drive = GetFullyQualifiedPath(Cwd);\r
- PathRemoveLastItem(Drive);\r
- FreePool(Cwd);\r
+ if (Cwd == NULL) {\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cd");\r
+ ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+ } else {\r
+ StrCpyS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, Directory);\r
+ StrCatS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, L"\\");\r
+ Drive = GetFullyQualifiedPath (Cwd);\r
+ PathRemoveLastItem (Drive);\r
+ FreePool (Cwd);\r
+ }\r
}\r
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
//\r
} else {\r
CwdSize = StrSize(Directory) + sizeof(CHAR16);\r
Cwd = AllocateZeroPool(CwdSize);\r
- ASSERT(Cwd!=NULL);\r
- StrCpyS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, Directory);\r
- StrCatS(Cwd, StrSize(Directory)/sizeof(CHAR16)+1, L"\\");\r
- Drive = GetFullyQualifiedPath(Cwd);\r
- while (PathRemoveLastItem(Drive));\r
- FreePool(Cwd);\r
+ if (Cwd == NULL) {\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cd");\r
+ ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+ } else {\r
+ StrCpyS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, Directory);\r
+ StrCatS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, L"\\");\r
+ Drive = GetFullyQualifiedPath (Cwd);\r
+ while (PathRemoveLastItem (Drive)) {\r
+ //\r
+ // Check if Drive contains 'fsx:\' only or still points to a sub-directory.\r
+ // Don't remove trailing '\' from Drive if it points to the root directory.\r
+ //\r
+ Path = StrStr (Drive, L":\\");\r
+ if ((Path != NULL) && (*(Path + 2) == CHAR_NULL)) {\r
+ break;\r
+ }\r
+ }\r
+ FreePool (Cwd);\r
+ }\r
}\r
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
//\r