Commit 7c315a93 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Fix a crash in belle_sip_header_address_parse() where it thinks there is a password and fails.

parent c7998b98
......@@ -387,16 +387,26 @@ scope { belle_generic_uri_t* current; }
: authority_user ( COLON authority_password )? AT ;
authority_user : ( unreserved | escaped | user_unreserved )+ {
char* unescaped_username;
unescaped_username=belle_sip_to_unescaped_string((const char *)$text->chars);
const char* source = (const char*)$text->chars;
if( source == NULL ){
belle_generic_uri_set_user($authority_userinfo::current,"");
} else {
unescaped_username=belle_sip_to_unescaped_string(source);
belle_generic_uri_set_user($authority_userinfo::current,unescaped_username);
belle_sip_free(unescaped_username);
}
};
authority_password : ( unreserved | escaped | AND | EQUAL | PLUS | DOLLARD | COMMA )* {
char* unescaped_userpasswd;
unescaped_userpasswd=belle_sip_to_unescaped_string((const char *)$text->chars);
const char* source = (const char*)$text->chars;
if( source == NULL ){
belle_generic_uri_set_user_password($authority_userinfo::current,"");
} else {
unescaped_userpasswd=belle_sip_to_unescaped_string((const char *)source);
belle_generic_uri_set_user_password($authority_userinfo::current,unescaped_userpasswd);
belle_sip_free(unescaped_userpasswd);
}
};
authority_hostport[belle_generic_uri_t* uri]
scope { belle_generic_uri_t* current; }
......@@ -1479,9 +1489,14 @@ user : ( unreserved | escaped | user_unreserved )+ {
};
password : ( unreserved | escaped |AND | EQUAL | PLUS | DOLLARD | COMMA )* {
char* unescaped_userpasswd;
unescaped_userpasswd=belle_sip_to_unescaped_string((const char *)$text->chars);
const char* source = (const char*)$text->chars;
if( source == NULL ){
belle_sip_uri_set_user_password($userinfo::current,"");
} else {
unescaped_userpasswd=belle_sip_to_unescaped_string((const char *)source);
belle_sip_uri_set_user_password($userinfo::current,unescaped_userpasswd);
belle_sip_free(unescaped_userpasswd);
}
};
hostport[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; }
......
......@@ -437,6 +437,25 @@ void test_escaping_bad_chars(void){
belle_sip_free(escaped);
}
static void test_strange_addresses(void){
/*
* These addresses are malformed and used to make the parser crash.
* They are here to test that everything fails gracefully now.
*/
static const char *addresses[] = {
"sip:France:@+330667441601",
"hello\xa0\xc8world",
};
unsigned int addr_count = sizeof(addresses)/sizeof(const char*);
unsigned int i;
for( i=0; i<addr_count; i++){
belle_sip_header_address_t* L_uri = belle_sip_header_address_parse(addresses[i]);
if(L_uri){
belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri));
}
}
}
static test_t uri_tests[] = {
{ "Simple URI", testSIMPLEURI },
......@@ -456,7 +475,8 @@ static test_t uri_tests[] = {
{ "URI equals", test_uri_equals },
{ "Simple URI error", testSIMPLEURI_error },
{ "IPv6 URI", testIPV6URI },
{ "URI components", testUriComponentsChecker }
{ "URI components", testUriComponentsChecker },
{ "Strange URIs", test_strange_addresses },
};
test_suite_t sip_uri_test_suite = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment