From 7b901e8b9b29f69a0465fc2326a115ed6c27aca5 Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Wed, 25 Jan 2017 09:14:32 +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 87ef7e0e6c..1e63c1bb1f 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -1297,6 +1297,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)]; + assert(sizeof(quotedOut) > 0); + quotedOut[0] = '\0'; + char *newout = NULL; int newfree = 0; @@ -1312,7 +1317,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.2