From: Star Zeng Date: Mon, 21 Jul 2014 03:05:20 +0000 (+0000) Subject: MdePkg BaseLib: Fix a corner case of Source and Destination overlap. X-Git-Tag: edk2-stable201903~11328 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=d52b9d864efb0ba4b812538c45aef0b617bace39 MdePkg BaseLib: Fix a corner case of Source and Destination overlap. The overlap may happen when the address of Destination in UnicodeStrToAsciiStr() or Source in AsciiStrToUnicodeStr() is not two bytes aligned. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Liming Gao git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15665 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c index 227a0dc846..9505c5b21e 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -1,7 +1,7 @@ /** @file Unicode and ASCII string primatives. - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1040,7 +1040,7 @@ UnicodeStrToAsciiStr ( // // Source and Destination should not overlap // - ASSERT ((UINTN) ((CHAR16 *) Destination - Source) > StrLen (Source)); + ASSERT ((UINTN) (Destination - (CHAR8 *) Source) >= StrSize (Source)); ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source)); @@ -2008,9 +2008,9 @@ AsciiStrToUnicodeStr ( // Source and Destination should not overlap // ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source)); - ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16))); + ASSERT ((UINTN) (Source - (CHAR8 *) Destination) >= (AsciiStrSize (Source) * sizeof (CHAR16))); + - ReturnValue = Destination; while (*Source != '\0') { *(Destination++) = (CHAR16) *(Source++);