Skip to content

Commit

Permalink
Fix errorPos for malformed URIs with IPvFuture addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
hartwork committed Dec 8, 2018
1 parent cef2502 commit d40786a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ NOTE: uriparser is looking for help with a few things:
mitigated if passed parameter <afterLast> points to readable memory
containing a '\0' byte.
Thanks to Joergen Ibsen for the report!
* Fixed: When parsing a malformed URI with an IPvFuture address
(e.g. "http://[vA.123456" missing "]"), errorPos would point to the first
character after "v" than the actual position of the error (here: the end
of the string)
* Fixed: uriToStringCharsRequired* reported 1 more byte than actually needed
for IPv4 address URIs (GitHub #41); Thanks to @gyh007 for the patch!
* Fixed: Compilation with MinGW
Expand Down
9 changes: 6 additions & 3 deletions src/UriParse.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,12 @@ static URI_INLINE const URI_CHAR * URI_FUNC(ParseIpLit2)(
if (afterIpFuture == NULL) {
return NULL;
}
if ((afterIpFuture >= afterLast)
|| (*afterIpFuture != _UT(']'))) {
URI_FUNC(StopSyntax)(state, first, memory);
if (afterIpFuture >= afterLast) {
URI_FUNC(StopSyntax)(state, afterLast, memory);
return NULL;
}
if (*afterIpFuture != _UT(']')) {
URI_FUNC(StopSyntax)(state, afterIpFuture, memory);
return NULL;
}
return afterIpFuture + 1;
Expand Down
10 changes: 10 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,16 @@ TEST(UriSuite, TestRangeComparisonRemoveBaseUriIssue19) {
"http://example2/x/y/z");
}

TEST(ErrorPosSuite, TestErrorPosIPvFuture) {
UriUriA uri;
const char * errorPos;

const char * const uriText = "http://[vA.123456"; // missing "]"
EXPECT_EQ(uriParseSingleUriA(&uri, uriText, &errorPos),
URI_ERROR_SYNTAX);
EXPECT_EQ(errorPos, uriText + strlen(uriText));
}

TEST(UriParseSingleSuite, Success) {
UriUriA uri;

Expand Down

0 comments on commit d40786a

Please sign in to comment.