From: Dragan Dosen Date: Mon, 25 Jul 2016 09:35:02 +0000 (+0200) Subject: BUG/MEDIUM: log: use function "escape_string" instead of "escape_chunk" X-Git-Tag: v1.7-dev4~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=db1b6f9ecb552d0337a1471305ad687084947d13;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: log: use function "escape_string" instead of "escape_chunk" In function lf_text_len(), we used escape_chunk() to escape special characters. There could be a problem if len is greater than the real src string length (zero-terminated), eg. when calling lf_text_len() from lf_text(). --- diff --git a/src/log.c b/src/log.c index 99c89f34d4..302e14a9da 100644 --- a/src/log.c +++ b/src/log.c @@ -830,19 +830,17 @@ char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct lo } if (src && len) { + if (++len > size) + len = size; if (node->options & LOG_OPT_ESC) { - struct chunk chunk; char *ret; - chunk_initlen(&chunk, (char *)src, 0, len); - ret = escape_chunk(dst, dst + size, '\\', rfc5424_escape_map, &chunk); + ret = escape_string(dst, dst + len, '\\', rfc5424_escape_map, src); if (ret == NULL || *ret != '\0') return NULL; len = ret - dst; } else { - if (++len > size) - len = size; len = strlcpy2(dst, src, len); }