summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library')
-rw-r--r--MdePkg/Library/BaseLib/SafeString.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/SafeString.c
index b7895adfc0..249fe477b4 100644
--- a/MdePkg/Library/BaseLib/SafeString.c
+++ b/MdePkg/Library/BaseLib/SafeString.c
@@ -1234,6 +1234,7 @@ StrToIpv6Address (
//
// Uintn won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4.
//
+ ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr));
LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8);
LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn;
AddressIndex += 2;
@@ -1286,11 +1287,13 @@ StrToIpv6Address (
}
CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart);
ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - AddressIndex);
- CopyMem (
- &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex],
- &LocalAddress.Addr[CompressStart],
- AddressIndex - CompressStart
- );
+ if (AddressIndex > CompressStart) {
+ CopyMem (
+ &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex],
+ &LocalAddress.Addr[CompressStart],
+ AddressIndex - CompressStart
+ );
+ }
if (PrefixLength != NULL) {
*PrefixLength = LocalPrefixLength;
@@ -3204,6 +3207,7 @@ AsciiStrToIpv6Address (
//
// Uintn won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4.
//
+ ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr));
LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8);
LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn;
AddressIndex += 2;
@@ -3256,11 +3260,13 @@ AsciiStrToIpv6Address (
}
CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart);
ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - AddressIndex);
- CopyMem (
- &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex],
- &LocalAddress.Addr[CompressStart],
- AddressIndex - CompressStart
- );
+ if (AddressIndex > CompressStart) {
+ CopyMem (
+ &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex],
+ &LocalAddress.Addr[CompressStart],
+ AddressIndex - CompressStart
+ );
+ }
if (PrefixLength != NULL) {
*PrefixLength = LocalPrefixLength;