aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authormnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b>2011-01-11 18:42:05 +0000
committermnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b>2011-01-11 18:42:05 +0000
commit0f64040a40ec1ae03061b4af1f89ea2c0ac85dc3 (patch)
treea1323fa0566bbddc321ee75ebac02e73cea55de1 /main
parentce672dec0365c99323d7feabed4546d75030e2db (diff)
Merged revisions 301305 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r301305 | mnicholson | 2011-01-11 12:34:40 -0600 (Tue, 11 Jan 2011) | 4 lines Prevent buffer overflows in ast_uri_encode() ABE-2705 ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@301307 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/utils.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/main/utils.c b/main/utils.c
index 4fe4984b2..871784563 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -386,28 +386,27 @@ char *ast_uri_encode(const char *string, char *outbuf, int buflen, int doreserve
char *reserved = ";/?:@&=+$,# "; /* Reserved chars */
const char *ptr = string; /* Start with the string */
- char *out = NULL;
- char *buf = NULL;
+ char *out = outbuf;
- ast_copy_string(outbuf, string, buflen);
-
- /* If there's no characters to convert, just go through and don't do anything */
- while (*ptr) {
+ /* If there's no characters to convert, just go through and copy the string */
+ while (*ptr && out - outbuf < buflen - 1) {
if ((*ptr < 32) || (doreserved && strchr(reserved, *ptr))) {
- /* Oops, we need to start working here */
- if (!buf) {
- buf = outbuf;
- out = buf + (ptr - string) ; /* Set output ptr */
+ if (out - outbuf >= buflen - 3) {
+ break;
}
+
out += sprintf(out, "%%%02x", (unsigned char) *ptr);
- } else if (buf) {
- *out = *ptr; /* Continue copying the string */
+ } else {
+ *out = *ptr; /* copy the character */
out++;
- }
+ }
ptr++;
}
- if (buf)
+
+ if (buflen) {
*out = '\0';
+ }
+
return outbuf;
}