BUG/MINOR: log: fix lf_text_len() truncate inconsistency
In c5bff8e550 ("BUG/MINOR: log: improper behavior when escaping log data")
we fixed lf_text_len() behavior with +E (escape) option.
However we introduced an inconsistency if output buffer is too small to
hold the whole output and truncation occurs: indeed without +E option up
to <size> bytes (including NULL byte) will be used whereas with +E option
only <size-1> bytes will be used. Fixing the function and related comment
so that the function behaves the same in regards to truncation whether +E
option is used or not.
This should be backported to all stable versions.
(cherry picked from commit b15f6dfae871f6ebfefa8a4e89958c1c70078e09)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 7b8ef8d23e34b2bb2bd2e91cfcf7b61125e9e09b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 1acf8c0e46fff90238467afe99a67511c9e98233)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit bb8b7630edf8cf5190c21baa13371b54a63aec6d)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
diff --git a/src/log.c b/src/log.c
index c112a49..b6fc584 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1386,13 +1386,12 @@
if (src && len) {
/* escape_string and strlcpy2 will both try to add terminating NULL-byte
- * to dst, so we need to make sure that extra byte will fit into dst
- * before calling them
+ * to dst
*/
if (node->options & LOG_OPT_ESC) {
char *ret;
- ret = escape_string(dst, (dst + size - 1), '\\', rfc5424_escape_map, src, src + len);
+ ret = escape_string(dst, dst + size, '\\', rfc5424_escape_map, src, src + len);
if (ret == NULL || *ret != '\0')
return NULL;
len = ret - dst;