v2: *Add a Url Parse state machine to indicate the host is ipv6 expressed url and can parse the ipv6 address correctly.
Cc: Fu Siyuan <siyuan...@intel.com> Cc: Ye Ting <ting...@intel.com> CC: Wu Jiaxin <jiaxin...@intel.com> CC: Gary Ching-Pang Lin <g...@suse.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zhang Lubo <lubo.zh...@intel.com> --- MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c index aeb52d0..500b3c7 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -68,10 +68,11 @@ typedef enum { UrlParserFragmentStart, // "#" UrlParserFragment, UrlParserUserInfo, UrlParserHostStart, // "@" UrlParserHost, + UrlParserHostIpv6, // "["(Ipv6 address) "]" UrlParserPortStart, // ":" UrlParserPort, UrlParserStateMax } HTTP_URL_PARSE_STATE; @@ -136,17 +137,20 @@ UriPercentDecode ( This function return the updated state accroding to the input state and next character of the authority. @param[in] Char Next character. @param[in] State Current value of the parser state machine. + @param[in] IsRightBracket TRUE if there is an sign ']' in the authority component and + indicates the next part is ':' before Port. @return Updated state value. **/ HTTP_URL_PARSE_STATE NetHttpParseAuthorityChar ( IN CHAR8 Char, - IN HTTP_URL_PARSE_STATE State + IN HTTP_URL_PARSE_STATE State, + IN BOOLEAN *IsRightBracket ) { // // RFC 3986: @@ -167,16 +171,31 @@ NetHttpParseAuthorityChar ( return UrlParserHostStart; } break; case UrlParserHost: - case UrlParserHostStart: + case UrlParserHostStart: + if (Char == '[') { + return UrlParserHostIpv6; + } + if (Char == ':') { return UrlParserPortStart; } + return UrlParserHost; - + + case UrlParserHostIpv6: + if (Char == ']') { + *IsRightBracket = TRUE; + } + + if (Char == ':' && *IsRightBracket == TRUE) { + return UrlParserPortStart; + } + return UrlParserHostIpv6; + case UrlParserPort: case UrlParserPortStart: return UrlParserPort; default: @@ -208,10 +227,11 @@ NetHttpParseAuthority ( CHAR8 *Authority; UINT32 Length; HTTP_URL_PARSE_STATE State; UINT32 Field; UINT32 OldField; + BOOLEAN IsrightBracket; ASSERT ((UrlParser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0); // // authority = [ userinfo "@" ] host [ ":" port ] @@ -220,16 +240,17 @@ NetHttpParseAuthority ( State = UrlParserUserInfo; } else { State = UrlParserHost; } + IsrightBracket = FALSE; Field = HTTP_URI_FIELD_MAX; OldField = Field; Authority = Url + UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Offset; Length = UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Length; for (Char = Authority; Char < Authority + Length; Char++) { - State = NetHttpParseAuthorityChar (*Char, State); + State = NetHttpParseAuthorityChar (*Char, State, &IsrightBracket); switch (State) { case UrlParserStateMax: return EFI_INVALID_PARAMETER; case UrlParserHostStart: @@ -241,10 +262,14 @@ NetHttpParseAuthority ( break; case UrlParserHost: Field = HTTP_URI_FIELD_HOST; break; + + case UrlParserHostIpv6: + Field = HTTP_URI_FIELD_HOST; + break; case UrlParserPort: Field = HTTP_URI_FIELD_PORT; break; -- 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel