MdeModulePkg:Fix a bug that HttpLib can not parse Ipv6 address correctly.

When parsing the authority component of the input URL, it can not distinguish 
the ":" is the flag that indicates the port or the separator between 
the ipv6 address.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Gary Ching-Pang Lin <glin@suse.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18744 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Zhang Lubo 2015-11-09 03:45:23 +00:00 committed by luobozhang
parent b659408b93
commit e91cc29dd7
1 changed files with 29 additions and 4 deletions

View File

@ -70,6 +70,7 @@ typedef enum {
UrlParserUserInfo, UrlParserUserInfo,
UrlParserHostStart, // "@" UrlParserHostStart, // "@"
UrlParserHost, UrlParserHost,
UrlParserHostIpv6, // "["(Ipv6 address) "]"
UrlParserPortStart, // ":" UrlParserPortStart, // ":"
UrlParserPort, UrlParserPort,
UrlParserStateMax UrlParserStateMax
@ -138,13 +139,16 @@ UriPercentDecode (
@param[in] Char Next character. @param[in] Char Next character.
@param[in] State Current value of the parser state machine. @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. @return Updated state value.
**/ **/
HTTP_URL_PARSE_STATE HTTP_URL_PARSE_STATE
NetHttpParseAuthorityChar ( NetHttpParseAuthorityChar (
IN CHAR8 Char, IN CHAR8 Char,
IN HTTP_URL_PARSE_STATE State IN HTTP_URL_PARSE_STATE State,
IN BOOLEAN *IsRightBracket
) )
{ {
@ -169,12 +173,27 @@ NetHttpParseAuthorityChar (
break; break;
case UrlParserHost: case UrlParserHost:
case UrlParserHostStart: case UrlParserHostStart:
if (Char == '[') {
return UrlParserHostIpv6;
}
if (Char == ':') { if (Char == ':') {
return UrlParserPortStart; return UrlParserPortStart;
} }
return UrlParserHost; return UrlParserHost;
case UrlParserHostIpv6:
if (Char == ']') {
*IsRightBracket = TRUE;
}
if (Char == ':' && *IsRightBracket == TRUE) {
return UrlParserPortStart;
}
return UrlParserHostIpv6;
case UrlParserPort: case UrlParserPort:
case UrlParserPortStart: case UrlParserPortStart:
return UrlParserPort; return UrlParserPort;
@ -210,6 +229,7 @@ NetHttpParseAuthority (
HTTP_URL_PARSE_STATE State; HTTP_URL_PARSE_STATE State;
UINT32 Field; UINT32 Field;
UINT32 OldField; UINT32 OldField;
BOOLEAN IsrightBracket;
ASSERT ((UrlParser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0); ASSERT ((UrlParser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0);
@ -222,12 +242,13 @@ NetHttpParseAuthority (
State = UrlParserHost; State = UrlParserHost;
} }
IsrightBracket = FALSE;
Field = HTTP_URI_FIELD_MAX; Field = HTTP_URI_FIELD_MAX;
OldField = Field; OldField = Field;
Authority = Url + UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Offset; Authority = Url + UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Offset;
Length = UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Length; Length = UrlParser->FieldData[HTTP_URI_FIELD_AUTHORITY].Length;
for (Char = Authority; Char < Authority + Length; Char++) { for (Char = Authority; Char < Authority + Length; Char++) {
State = NetHttpParseAuthorityChar (*Char, State); State = NetHttpParseAuthorityChar (*Char, State, &IsrightBracket);
switch (State) { switch (State) {
case UrlParserStateMax: case UrlParserStateMax:
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -243,6 +264,10 @@ NetHttpParseAuthority (
case UrlParserHost: case UrlParserHost:
Field = HTTP_URI_FIELD_HOST; Field = HTTP_URI_FIELD_HOST;
break; break;
case UrlParserHostIpv6:
Field = HTTP_URI_FIELD_HOST;
break;
case UrlParserPort: case UrlParserPort:
Field = HTTP_URI_FIELD_PORT; Field = HTTP_URI_FIELD_PORT;