Commit b757b258 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Fix crash when string to escape is in utf8

parent d9661acb
......@@ -991,7 +991,7 @@ static char* belle_sip_escape(const char* buff, const char *noescapes) {
int out_buff_index=0;
for(i=0; buff[i] != '\0'; i++) {
int c = buff[i];
int c = ((unsigned char*)buff)[i];
if (outbuf_size<out_buff_index-3){
outbuf_size+=MAX(orig_size/2,3);
output_buff=belle_sip_realloc(output_buff,outbuf_size+1);
......
......@@ -18,6 +18,7 @@
#include "belle-sip/belle-sip.h"
#include "belle_sip_tester.h"
#include "belle_sip_internal.h"
#include <stdio.h>
#include "CUnit/Basic.h"
......@@ -428,10 +429,21 @@ void testUriComponentsChecker() {
}
}
void test_escaping_bad_chars(void){
char bad_uri[13] = { 'h', 'e', 'l', 'l', 'o', (char)0xa0, (char)0xc8, 'w', 'o', 'r', 'l', 'd', 0x0 };
char *escaped = belle_sip_uri_to_escaped_username(bad_uri);
CU_ASSERT_STRING_EQUAL(escaped, "hello%a0%c8world");
belle_sip_free(escaped);
}
static test_t uri_tests[] = {
{ "Simple URI", testSIMPLEURI },
{ "Complex URI", testCOMPLEXURI },
{ "Escaped username", test_escaped_username },
{ "Escaped username with bad chars", test_escaping_bad_chars },
{ "Escaped parameter", test_escaped_parameter },
{ "Escaped passwd", test_escaped_passwd},
{ "User passwd", test_user_passwd},
......
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