From: Eduard Bagdasaryan Date: Sun, 15 Jan 2017 17:35:43 +0000 (+1300) Subject: Fix "Source and destination overlap in memcpy" Valgrind errors X-Git-Tag: M-staged-PR71~306 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=051b132b350cb5b92689628fb56f5755be693bcb;p=thirdparty%2Fsquid.git 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. --- 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;