Commit 89c54de6 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix bug in belle_sip_escape()

parent e79a99aa
......@@ -1028,22 +1028,23 @@ static const char *get_sip_uri_header_noescapes(void) {
static char* belle_sip_escape(const char* buff, const char *noescapes) {
size_t outbuf_size=strlen(buff);
size_t orig_size=outbuf_size;
char *output_buff=(char*)belle_sip_malloc(outbuf_size+1);
char *output_buff=(char*)belle_sip_malloc(outbuf_size + 1);
int i;
size_t out_buff_index=0;
for(i=0; buff[i] != '\0'; i++) {
int c = ((unsigned char*)buff)[i];
if (outbuf_size < out_buff_index + 3){
// we will possibly add 3 chars
outbuf_size+=MAX(orig_size/2,3);
output_buff=belle_sip_realloc(output_buff,outbuf_size+1);
}
if (noescapes[c] == 1) {
output_buff[out_buff_index++]=c;
} else {
if (outbuf_size < out_buff_index + 3){
// we will possibly add 3 chars
outbuf_size += MAX(orig_size/2,3);
output_buff = belle_sip_realloc(output_buff, outbuf_size + 1);
}
// this will write 3 characters
out_buff_index+=snprintf(output_buff+out_buff_index,outbuf_size-out_buff_index,"%%%02x", c);
out_buff_index+=snprintf(output_buff+out_buff_index, outbuf_size +1 - out_buff_index, "%%%02x", c);
}
}
output_buff[out_buff_index]='\0';
......
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