Before this patch, source and destination arguments in
log_quoted_string() could point to the same static memory area, causing
multiple Valgrind-reported errors. Fixed by creating another buffer to
store quoted-processed output string.
if (out && *out) {
if (quote || fmt->quote != LOG_QUOTE_NONE) {
+ // Do not write to the tmp buffer because it may contain the to-be-quoted value.
+ static char quotedOut[2 * sizeof(tmp)];
+ static_assert(sizeof(quotedOut) > 0, "quotedOut has zero length");
+ quotedOut[0] = '\0';
+
char *newout = NULL;
int newfree = 0;
newout = (char *)xmalloc(out_len);
newfree = 1;
} else
- newout = tmp;
+ newout = quotedOut;
log_quoted_string(out, newout);
}
break;