From 775455633400aaba9161b5bb97b48f0df059bd88 Mon Sep 17 00:00:00 2001 From: jjin9 Date: Fri, 6 Aug 2010 08:31:00 +0000 Subject: =?UTF-8?q?Fix=20IP=20address=20text=20representation=20issue=20ab?= =?UTF-8?q?out=20leading=20zeros=201.It=20keeps=20the=20rule=20that=20Lead?= =?UTF-8?q?ing=20zero=E2=80=99s=20compression(Yes/Not)=20need=20to=20be=20?= =?UTF-8?q?consistent=20throughout=20the=20whole=20IP=20address.=202.It=20?= =?UTF-8?q?also=20fixes=20some=20issue=20to=20recognize=20some=20invalid?= =?UTF-8?q?=20representation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10777 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 59 ++++++++++++++++++++++++++++-- 1 file 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); -- cgit v1.2.3