1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05: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 commit is contained in:
Philipp Schafft 2015-04-08 09:02:20 +00:00
parent 170b75b31b
commit 3baa4e46aa

View File

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