From d52b9d864efb0ba4b812538c45aef0b617bace39 Mon Sep 17 00:00:00 2001 From: Star Zeng Date: Mon, 21 Jul 2014 03:05:20 +0000 Subject: [PATCH] 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 --- MdePkg/Library/BaseLib/String.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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++);