diff options
Diffstat (limited to 'server/util.c')
-rw-r--r-- | server/util.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/server/util.c b/server/util.c index 46741dd8b1..d332c38990 100644 --- a/server/util.c +++ b/server/util.c @@ -1850,12 +1850,26 @@ AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str) char *ret; unsigned char *d; const unsigned char *s; + int length = 0; if (!str) { return NULL; } - ret = apr_palloc(p, 4 * strlen(str) + 1); /* Be safe */ + /* First, compute the space needed for the escaped string. + * This could be tweaked a bit for '\b', '\n'... These characters + * should not be common, so do not bother. */ + s = (const unsigned char *)str; + for (; *s; ++s) { + if (TEST_CHAR(*s, T_ESCAPE_LOGITEM)) { + length += 4; /* for '\\' + c2x() */ + } + else { + length++; + } + } + + ret = apr_palloc(p, length + 1); d = (unsigned char *)ret; s = (const unsigned char *)str; for (; *s; ++s) { |