1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-06-23 06:25:24 +00:00

Fix: Let util_url_escape() handle NULL parameter.

This let util_url_escape() handle NULL passed as parameter.
In case the parameter is NULL it will also return NULL.

This patch also does some cleanup of the code such as migration
away from int and thus avoiding future failtures.

This is a re-apply of 3baa4e46aa
as git refuses to cherry-pick.
This commit is contained in:
Philipp Schafft 2015-04-08 10:25:25 +00:00
parent c1f0eaff8a
commit 6605f4ddaa

View File

@ -265,21 +265,25 @@ static char safechars[256] = {
char *util_url_escape (const char *src)
{
int len = strlen(src);
/* Efficiency not a big concern here, keep the code simple/conservative */
char *dst = calloc(1, len*3 + 1);
size_t len;
char *dst;
unsigned char *source = (unsigned char *)src;
int i,j=0;
size_t i, j;
for(i=0; i < len; i++) {
if (!src)
return NULL;
len = strlen(src);
/* Efficiency not a big concern here, keep the code simple/conservative */
dst = calloc(1, len*3 + 1);
for(i = 0, j = 0; i < len; i++) {
if(safechars[source[i]]) {
dst[j++] = source[i];
}
else {
dst[j] = '%';
dst[j+1] = hexchars[ (source[i] >> 4) & 0xf ];
dst[j+2] = hexchars[ source[i] & 0xf ];
j+= 3;
} else {
dst[j++] = '%';
dst[j++] = hexchars[(source[i] >> 4) & 0x0F];
dst[j++] = hexchars[ source[i] & 0x0F];
}
}