summaryrefslogtreecommitdiff
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>2010-08-06 08:31:00 +0000
committerjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>2010-08-06 08:31:00 +0000
commit775455633400aaba9161b5bb97b48f0df059bd88 (patch)
tree2db8897b2618bda255c7210dca0f35afbde107c2 /MdeModulePkg
parent1a2ae0f71f51c1bc52576ce99647513a29f71d98 (diff)
downloadedk2-platforms-775455633400aaba9161b5bb97b48f0df059bd88.tar.xz
Fix IP address text representation issue about leading zeros
1.It keeps the rule that Leading zero’s compression(Yes/Not) need to be consistent throughout the whole IP address. 2.It also fixes some issue to recognize some invalid representation. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10777 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Library/DxeNetLib/DxeNetLib.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index c055db2b77..5bad2f13a6 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -2808,13 +2808,17 @@ NetLibAsciiStrToIp6 (
UINTN NodeVal;
BOOLEAN Short;
BOOLEAN Update;
+ BOOLEAN LeadZero;
+ UINT8 LeadZeroCnt;
+ UINT8 Cnt;
if ((String == NULL) || (Ip6Address == NULL)) {
return EFI_INVALID_PARAMETER;
}
- Ip6Str = (CHAR8 *) String;
- AllowedCnt = 6;
+ Ip6Str = (CHAR8 *) String;
+ AllowedCnt = 6;
+ LeadZeroCnt = 0;
//
// An IPv6 address leading with : looks strange.
@@ -2833,6 +2837,7 @@ NetLibAsciiStrToIp6 (
TailNodeCnt = 0;
Short = FALSE;
Update = FALSE;
+ LeadZero = FALSE;
for (Index = 0; Index < 15; Index = (UINT8) (Index + 2)) {
TempStr = Ip6Str;
@@ -2847,12 +2852,17 @@ NetLibAsciiStrToIp6 (
if (*Ip6Str == ':') {
if (*(Ip6Str + 1) == ':') {
- if ((*(Ip6Str + 2) == '0') || (NodeCnt > 6)) {
+ if ((NodeCnt > 6) ||
+ ((*(Ip6Str + 2) != '\0') && (AsciiStrHexToUintn (Ip6Str + 2) == 0))) {
//
// ::0 looks strange. report error to user.
//
return EFI_INVALID_PARAMETER;
}
+ if ((NodeCnt == 6) && (*(Ip6Str + 2) != '\0') &&
+ (AsciiStrHexToUintn (Ip6Str + 2) != 0)) {
+ return EFI_INVALID_PARAMETER;
+ }
//
// Skip the abbreviation part of IPv6 address.
@@ -2884,6 +2894,9 @@ NetLibAsciiStrToIp6 (
Ip6Str = Ip6Str + 2;
} else {
+ if (*(Ip6Str + 1) == '\0') {
+ return EFI_INVALID_PARAMETER;
+ }
Ip6Str++;
NodeCnt++;
if ((Short && (NodeCnt > 6)) || (!Short && (NodeCnt > 7))) {
@@ -2903,6 +2916,46 @@ NetLibAsciiStrToIp6 (
if ((NodeVal > 0xFFFF) || (Index > 14)) {
return EFI_INVALID_PARAMETER;
}
+ if (NodeVal != 0) {
+ if ((*TempStr == '0') &&
+ ((*(TempStr + 2) == ':') || (*(TempStr + 3) == ':') ||
+ (*(TempStr + 2) == '\0') || (*(TempStr + 3) == '\0'))) {
+ return EFI_INVALID_PARAMETER;
+ }
+ if ((*TempStr == '0') && (*(TempStr + 4) != '\0') &&
+ (*(TempStr + 4) != ':')) {
+ return EFI_INVALID_PARAMETER;
+ }
+ } else {
+ if (((*TempStr == '0') && (*(TempStr + 1) == '0') &&
+ ((*(TempStr + 2) == ':') || (*(TempStr + 2) == '\0'))) ||
+ ((*TempStr == '0') && (*(TempStr + 1) == '0') && (*(TempStr + 2) == '0') &&
+ ((*(TempStr + 3) == ':') || (*(TempStr + 3) == '\0')))) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ Cnt = 0;
+ while ((TempStr[Cnt] != ':') && (TempStr[Cnt] != '\0')) {
+ Cnt++;
+ }
+ if (LeadZeroCnt == 0) {
+ if ((Cnt == 4) && (*TempStr == '0')) {
+ LeadZero = TRUE;
+ LeadZeroCnt++;
+ }
+ if ((Cnt != 0) && (Cnt < 4)) {
+ LeadZero = FALSE;
+ LeadZeroCnt++;
+ }
+ } else {
+ if ((Cnt == 4) && (*TempStr == '0') && (LeadZero == FALSE)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ if ((Cnt != 0) && (Cnt < 4) && (LeadZero == TRUE)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
Ip6Address->Addr[Index] = (UINT8) (NodeVal >> 8);
Ip6Address->Addr[Index + 1] = (UINT8) (NodeVal & 0xFF);