Fix core dump when ip address is used in url

This commit is contained in:
Ai Lin Chia
2016-05-25 17:55:29 +02:00
parent 59d431c3b1
commit 364faee241
3 changed files with 54 additions and 29 deletions

46
Url.cpp

@ -755,31 +755,35 @@ static void stripParameters( UrlParser *urlParser ) {
/// @todo ALC cater for more affiliate links here
if ( strncmp( urlParser->getDomain(), "amazon.", 7 ) == 0 ) {
// amazon
// https://www.reddit.com/r/GameDeals/wiki/affiliate
// only check domain specific logic when we have a domain
if ( urlParser->getDomain() ) {
if ( strncmp( urlParser->getDomain(), "amazon.", 7 ) == 0 ) {
// amazon
// https://www.reddit.com/r/GameDeals/wiki/affiliate
// affiliate
urlParser->removeQueryParam( "tag" );
// affiliate
urlParser->removeQueryParam( "tag" );
// wishlist
urlParser->removeQueryParam( "coliid" );
urlParser->removeQueryParam( "colid" );
// wishlist
urlParser->removeQueryParam( "coliid" );
urlParser->removeQueryParam( "colid" );
// reference
urlParser->removeQueryParam( "ref" );
urlParser->removePathParam( UrlComponent::Matcher( "ref" ), UrlComponent::Validator( 0, 0, false, ALLOW_ALL, MANDATORY_PUNCTUATION ) );
} else if ( strncmp( urlParser->getDomain(), "ebay.", 5 ) == 0 ) {
// ebay
// http://www.ebaypartnernetworkblog.com/en/2009/05/new-link-generator-tool-additional-information/
// reference
urlParser->removeQueryParam( "ref" );
urlParser->removePathParam( UrlComponent::Matcher( "ref" ),
UrlComponent::Validator( 0, 0, false, ALLOW_ALL, MANDATORY_PUNCTUATION ) );
} else if ( strncmp( urlParser->getDomain(), "ebay.", 5 ) == 0 ) {
// ebay
// http://www.ebaypartnernetworkblog.com/en/2009/05/new-link-generator-tool-additional-information/
urlParser->removeQueryParam( "icep_ff3" );
urlParser->removeQueryParam( "pub" );
urlParser->removeQueryParam( "toolid" );
urlParser->removeQueryParam( "campid" );
urlParser->removeQueryParam( "customid" );
urlParser->removeQueryParam( "afepn" );
urlParser->removeQueryParam( "pid" );
urlParser->removeQueryParam( "icep_ff3" );
urlParser->removeQueryParam( "pub" );
urlParser->removeQueryParam( "toolid" );
urlParser->removeQueryParam( "campid" );
urlParser->removeQueryParam( "customid" );
urlParser->removeQueryParam( "afepn" );
urlParser->removeQueryParam( "pid" );
}
}
}

@ -97,7 +97,7 @@ void UrlParser::parse() {
const char *userInfoPos = static_cast<const char *>( memchr( m_authority, '@', m_authorityLen ) );
if ( userInfoPos != NULL ) {
m_host = userInfoPos + 1;
m_hostLen = m_authorityLen - ( userInfoPos - m_authority );
m_hostLen = m_authorityLen - ( userInfoPos - m_authority ) - 1;
} else {
m_host = m_authority;
m_hostLen = m_authorityLen;
@ -119,14 +119,11 @@ void UrlParser::parse() {
if ( m_domain ) {
m_domain += 1;
m_domainLen = m_hostLen - ( m_domain - m_host );
} else {
m_domain = m_host;
m_domainLen = m_hostLen;
}
}
// defaults to host
if ( !m_domain ) {
m_domain = m_host;
m_domainLen = m_hostLen;
}
}
const char *queryPos = static_cast<const char*>( memchr( currentPos, '?', urlEnd - currentPos ) );

@ -30,6 +30,14 @@ TEST( UrlParserTest, ParseSchemeNone ) {
}
TEST( UrlParserTest, ParseUserInfo ) {
std::string url( "http://username:password@www.example.com/param1=abc-123" );
UrlParser urlParser( url.c_str(), url.size() );
checkResult( "username:password@www.example.com", urlParser.getAuthority(), urlParser.getAuthorityLen() );
checkResult( "example.com", urlParser.getDomain(), urlParser.getDomainLen() );
}
TEST( UrlParserTest, ParseUserInfoPort ) {
std::string url( "http://username:password@www.example.com:8080/param1=abc-123" );
UrlParser urlParser( url.c_str(), url.size() );
@ -53,6 +61,22 @@ TEST( UrlParserTest, ParsePortSchemeNone ) {
checkResult( "example.com", urlParser.getDomain(), urlParser.getDomainLen() );
}
TEST( UrlParserTest, ParseIP ) {
std::string url( "http://127.0.0.1/param1=abc-123" );
UrlParser urlParser( url.c_str(), url.size() );
checkResult( "127.0.0.1", urlParser.getAuthority(), urlParser.getAuthorityLen() );
checkResult( "", urlParser.getDomain(), urlParser.getDomainLen() );
}
TEST( UrlParserTest, ParseIPPort ) {
std::string url( "http://127.0.0.1:8080/param1=abc-123" );
UrlParser urlParser( url.c_str(), url.size() );
checkResult( "127.0.0.1:8080", urlParser.getAuthority(), urlParser.getAuthorityLen() );
checkResult( "", urlParser.getDomain(), urlParser.getDomainLen() );
}
TEST( UrlParserTest, ParseSubdomainNone ) {
std::string url( "http://example.com/param1=abc-123" );
UrlParser urlParser( url.c_str(), url.size() );
@ -83,7 +107,7 @@ TEST( UrlParserTest, ParseTLDNone ) {
UrlParser urlParser( url.c_str(), url.size() );
checkResult( "ok", urlParser.getAuthority(), urlParser.getAuthorityLen() );
checkResult( "ok", urlParser.getDomain(), urlParser.getDomainLen() );
checkResult( "", urlParser.getDomain(), urlParser.getDomainLen() );
}
TEST( UrlParserTest, ParseSLD ) {