summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c b/MdeModulePkg/Universal/BdsDxe/BootMaint/BootOption.c
index 903ecfc..020d63a 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;
}