switch_url_encode now takes the full length of the buffer and null-terminates the string properly (Klocwork #1030)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8510 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Stefan Knoblich
2008-05-21 21:31:17 +00:00
parent a35dddbfc0
commit 5d91bea365
6 changed files with 16 additions and 14 deletions

View File

@@ -1415,15 +1415,18 @@ SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len)
return 0;
}
memset(buf, 0, len);
if (!url) {
return 0;
}
len--;
for (p = url; *p; p++) {
if (x >= len) {
break;
}
if (*p < ' ' || *p > '~' || strchr(urlunsafe, *p)) {
if ((x + 3) > len) {
if ((x + 3) >= len) {
break;
}
buf[x++] = '%';
@@ -1432,10 +1435,9 @@ SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len)
} else {
buf[x++] = *p;
}
if (x == len) {
break;
}
}
buf[x] = '\0';
return x;
}