From 11c11e4ecf4c3bb41ede73fe88ac29dc67195aa9 Mon Sep 17 00:00:00 2001 From: qwang12 Date: Wed, 23 Jul 2008 12:45:44 +0000 Subject: Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings that overlap. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5559 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/BdsDxe/BootMaint/BootOption.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'MdeModulePkg/Universal/BdsDxe') diff --git a/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c b/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c index 903ecfcdd3..020d63a8c6 100644 --- a/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c +++ b/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c @@ -1080,6 +1080,7 @@ BOpt_AppendFileName ( UINTN Size1; UINTN Size2; CHAR16 *Str; + CHAR16 *TmpStr; CHAR16 *Ptr; CHAR16 *LastSlash; @@ -1088,6 +1089,9 @@ BOpt_AppendFileName ( Str = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16)); ASSERT (Str != NULL); + TmpStr = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16)); + ASSERT (TmpStr != NULL); + StrCat (Str, Str1); if (!((*Str == '\\') && (*(Str + 1) == 0))) { StrCat (Str, L"\\"); @@ -1104,13 +1108,25 @@ BOpt_AppendFileName ( // DO NOT convert the .. if it is at the end of the string. This will // break the .. behavior in changing directories. // - StrCpy (LastSlash, Ptr + 3); + + // + // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings + // that overlap. + // + StrCpy (TmpStr, Ptr + 3); + StrCpy (LastSlash, TmpStr); Ptr = LastSlash; } else if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '\\') { // // Convert a "\.\" to a "\" // - StrCpy (Ptr, Ptr + 2); + + // + // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings + // that overlap. + // + StrCpy (TmpStr, Ptr + 2); + StrCpy (Ptr, TmpStr); Ptr = LastSlash; } else if (*Ptr == '\\') { LastSlash = Ptr; @@ -1119,6 +1135,8 @@ BOpt_AppendFileName ( Ptr++; } + FreePool (TmpStr); + return Str; } -- cgit v1.2.3