From 6a352324b99bf3c5e5b221781e9926c81c311748 Mon Sep 17 00:00:00 2001
From: qwang12
Date: Tue, 13 Feb 2007 01:47:44 +0000
Subject: [PATCH] Update all String related functions in BaseLib for this
change introduced in Mde Library Spec 0.60e: "Updated all functions that take
pointers to Unicode strings as parameters to ASSERT() if the pointer is not
aligned in a 16bit boundary."
gitsvnid: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2375 6f19259b4bc34df78a09765794883524

MdePkg/Include/Library/BaseLib.h  36 +++++++++++++++++++++
MdePkg/Library/BaseLib/BaseLib.msa  10 
MdePkg/Library/BaseLib/String.c  28 ++++++++++++++++++
3 files changed, 49 insertions(+), 25 deletions()
diff git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index e1d79e325c..bca5b735f8 100644
 a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ 139,7 +139,9 @@ typedef struct {
overlap, then the results are undefined.
If Destination is NULL, then ASSERT().
+ If Destination is not aligned on a 16bit boundary, then ASSERT().
If Source is NULL, then ASSERT().
+ If Source is not aligned on a 16bit boundary, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
@@ 170,8 +172,10 @@ StrCpy (
characters. If Source and Destination overlap, then the results are
undefined.
 If Destination is NULL, then ASSERT().
 If Source is NULL, then ASSERT().
+ If Length > 0 and Destination is NULL, then ASSERT().
+ If Length > 0 and Destination is not aligned on a 16bit boundary, then ASSERT().
+ If Length > 0 and Source is NULL, then ASSERT().
+ If Length > 0 and Source is not aligned on a 16bit bounadry, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
@@ 198,6 +202,7 @@ StrnCpy (
Unicode string specified by String.
If String is NULL, then ASSERT().
+ If String is not aligned on a 16bit boundary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and String contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 220,6 +225,7 @@ StrLen (
string specified by String.
If String is NULL, then ASSERT().
+ If String is not aligned on a 16bit boundary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and String contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 245,7 +251,9 @@ StrSize (
mismatched Unicode character in FirstString.
If FirstString is NULL, then ASSERT().
+ If FirstString is not aligned on a 16bit boundary, then ASSERT().
If SecondString is NULL, then ASSERT().
+ If SecondString is not aligned on a 16bit boundary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
than PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 277,8 +285,10 @@ StrCmp (
value returned is the first mismatched Unicode character in SecondString
subtracted from the first mismatched Unicode character in FirstString.
 If FirstString is NULL, then ASSERT().
 If SecondString is NULL, then ASSERT().
+ If Length > 0 and FirstString is NULL, then ASSERT().
+ If Length > 0 and FirstString is not aligned on a 16bit bounadary, then ASSERT().
+ If Length > 0 and SecondString is NULL, then ASSERT().
+ If Length > 0 and SecondString is not aligned on a 16bit bounadary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
than PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 312,7 +322,9 @@ StrnCmp (
results are undefined.
If Destination is NULL, then ASSERT().
+ If Destination is not aligned on a 16bit bounadary, then ASSERT().
If Source is NULL, then ASSERT().
+ If Source is not aligned on a 16bit bounadary, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
than PcdMaximumUnicodeStringLength Unicode characters not including the
@@ 351,7 +363,9 @@ StrCat (
the results are undefined.
If Destination is NULL, then ASSERT().
 If Source is NULL, then ASSERT().
+ If Length > 0 and Destination is not aligned on a 16bit boundary, then ASSERT().
+ If Length > 0 and Source is NULL, then ASSERT().
+ If Length > 0 and Source is not aligned on a 16bit boundary, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
than PcdMaximumUnicodeStringLength Unicode characters not including the
@@ 588,6 +602,7 @@ StrHexToUint64 (
If Destination is NULL, then ASSERT().
If Source is NULL, then ASSERT().
+ If Source is not aligned on a 16bit boundary, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Source contains
@@ 677,7 +692,8 @@ AsciiStrnCpy (
This function returns the number of ASCII characters in the Nullterminated
ASCII string specified by String.
 If String is NULL, then ASSERT().
+ If Length > 0 and Destination is NULL, then ASSERT().
+ If Length > 0 and Source is NULL, then ASSERT().
If PcdMaximumAsciiStringLength is not zero and String contains more than
PcdMaximumAsciiStringLength ASCII characters not including the Nullterminator,
then ASSERT().
@@ 792,8 +808,8 @@ AsciiStriCmp (
is the first mismatched ASCII character in SecondString subtracted from the
first mismatched ASCII character in FirstString.
 If FirstString is NULL, then ASSERT().
 If SecondString is NULL, then ASSERT().
+ If Length > 0 and FirstString is NULL, then ASSERT().
+ If Length > 0 and SecondString is NULL, then ASSERT().
If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
PcdMaximumAsciiStringLength ASCII characters not including the Nullterminator,
then ASSERT().
@@ 861,8 +877,8 @@ AsciiStrCat (
Destination is returned unmodified. If Source and Destination overlap, then
the results are undefined.
 If Destination is NULL, then ASSERT().
 If Source is NULL, then ASSERT().
+ If Length > 0 and Destination is NULL, then ASSERT().
+ If Length > 0 and Source is NULL, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
PcdMaximumAsciiStringLength ASCII characters not including the Nullterminator,
diff git a/MdePkg/Library/BaseLib/BaseLib.msa b/MdePkg/Library/BaseLib/BaseLib.msa
index 7e4c870b4f..fa8e8ed4dd 100644
 a/MdePkg/Library/BaseLib/BaseLib.msa
+++ b/MdePkg/Library/BaseLib/BaseLib.msa
@@ 1,14 +1,4 @@

BaseLib
diff git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index fefadc4337..3236f4cfa6 100644
 a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ 25,7 +25,9 @@
overlap, then the results are undefined.
If Destination is NULL, then ASSERT().
+ If Destination is not aligned on a 16bit boundary, then ASSERT().
If Source is NULL, then ASSERT().
+ If Source is not aligned on a 16bit boundary, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
@@ 50,6 +52,7 @@ StrCpy (
// Destination cannot be NULL
//
ASSERT (Destination != NULL);
+ ASSERT (((UINTN) Destination & 0x01) == 0);
//
// Destination and source cannot overlap
@@ 78,8 +81,10 @@ StrCpy (
characters. If Source and Destination overlap, then the results are
undefined.
 If Destination is NULL, then ASSERT().
 If Source is NULL, then ASSERT().
+ If Length > 0 and Destination is NULL, then ASSERT().
+ If Length > 0 and Destination is not aligned on a 16bit boundary, then ASSERT().
+ If Length > 0 and Source is NULL, then ASSERT().
+ If Length > 0 and Source is not aligned on a 16bit bounadry, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
@@ 110,6 +115,7 @@ StrnCpy (
// Destination cannot be NULL if Length is not zero
//
ASSERT (Destination != NULL);
+ ASSERT (((UINTN) Destination & 0x01) == 0);
//
// Destination and source cannot overlap
@@ 136,6 +142,7 @@ StrnCpy (
Unicode string specified by String.
If String is NULL, then ASSERT().
+ If String is not aligned on a 16bit boundary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and String contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 154,6 +161,7 @@ StrLen (
UINTN Length;
ASSERT (String != NULL);
+ ASSERT (((UINTN) String & 0x01) == 0);
for (Length = 0; *String != L'\0'; String++, Length++) {
//
@@ 175,6 +183,7 @@ StrLen (
string specified by String.
If String is NULL, then ASSERT().
+ If String is not aligned on a 16bit boundary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and String contains more than
PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 204,7 +213,9 @@ StrSize (
mismatched Unicode character in FirstString.
If FirstString is NULL, then ASSERT().
+ If FirstString is not aligned on a 16bit boundary, then ASSERT().
If SecondString is NULL, then ASSERT().
+ If SecondString is not aligned on a 16bit boundary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
than PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 250,8 +261,10 @@ StrCmp (
value returned is the first mismatched Unicode character in SecondString
subtracted from the first mismatched Unicode character in FirstString.
 If FirstString is NULL, then ASSERT().
 If SecondString is NULL, then ASSERT().
+ If Length > 0 and FirstString is NULL, then ASSERT().
+ If Length > 0 and FirstString is not aligned on a 16bit bounadary, then ASSERT().
+ If Length > 0 and SecondString is NULL, then ASSERT().
+ If Length > 0 and SecondString is not aligned on a 16bit bounadary, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
than PcdMaximumUnicodeStringLength Unicode characters not including the
Nullterminator, then ASSERT().
@@ 358,7 +371,9 @@ StrCat (
the results are undefined.
If Destination is NULL, then ASSERT().
 If Source is NULL, then ASSERT().
+ If Length > 0 and Destination is not aligned on a 16bit boundary, then ASSERT().
+ If Length > 0 and Source is NULL, then ASSERT().
+ If Length > 0 and Source is not aligned on a 16bit boundary, then ASSERT().
If Source and Destination overlap, then ASSERT().
If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
than PcdMaximumUnicodeStringLength Unicode characters not including the
@@ 789,6 +804,7 @@ StrHexToUintn (
UINTN Result;
ASSERT (String != NULL);
+ ASSERT (((UINTN) String & 0x01) == 0);
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
//
@@ 880,6 +896,7 @@ StrHexToUint64 (
UINT64 Result;
ASSERT (String != NULL);
+ ASSERT (((UINTN) String & 0x01) == 0);
ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));
//
@@ 1017,6 +1034,7 @@ UnicodeStrToAsciiStr (
{
ASSERT (Destination != NULL);
ASSERT (Source != NULL);
+ ASSERT (((UINTN) Source & 0x01) == 0);
//
// Source and Destination should not overlap

2.20.1