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.
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;