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.
This commit is contained in:
Aurelien DARRAGON 2024-04-09 11:15:23 +02:00
parent 0db8b6034d
commit b15f6dfae8

View File

@ -1841,13 +1841,12 @@ char *lf_text_len(char *dst, const char *src, size_t len, size_t size, const str
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;