From 051b132b350cb5b92689628fb56f5755be693bcb Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Mon, 16 Jan 2017 06:35:43 +1300 Subject: [PATCH] Fix "Source and destination overlap in memcpy" Valgrind errors 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. --- src/format/Format.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/format/Format.cc b/src/format/Format.cc index 91ba5fee31..7c18b0b855 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -1467,6 +1467,11 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS 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; @@ -1482,7 +1487,7 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS newout = (char *)xmalloc(out_len); newfree = 1; } else - newout = tmp; + newout = quotedOut; log_quoted_string(out, newout); } break; -- 2.47.3