]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg BaseLib: Fix a corner case of Source and Destination overlap.
authorStar Zeng <star.zeng@intel.com>
Mon, 21 Jul 2014 03:05:20 +0000 (03:05 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 21 Jul 2014 03:05:20 +0000 (03:05 +0000)
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 <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15665 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BaseLib/String.c

index 227a0dc846dc42d56a070e765003fe25db69e58e..9505c5b21ecb210f39fd51fa8472ec418f68fdae 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Unicode and ASCII string primatives.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2014, 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
@@ -1040,7 +1040,7 @@ UnicodeStrToAsciiStr (
   //\r
   // Source and Destination should not overlap\r
   //\r
-  ASSERT ((UINTN) ((CHAR16 *) Destination -  Source) > StrLen (Source));\r
+  ASSERT ((UINTN) (Destination - (CHAR8 *) Source) >= StrSize (Source));\r
   ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source));\r
 \r
 \r
@@ -2008,9 +2008,9 @@ AsciiStrToUnicodeStr (
   // Source and Destination should not overlap\r
   //\r
   ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));\r
-  ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));\r
+  ASSERT ((UINTN) (Source - (CHAR8 *) Destination) >= (AsciiStrSize (Source) * sizeof (CHAR16)));\r
+\r
 \r
\r
   ReturnValue = Destination;\r
   while (*Source != '\0') {\r
     *(Destination++) = (CHAR16) *(Source++);\r