]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix "Source and destination overlap in memcpy" Valgrind errors
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Sun, 15 Jan 2017 17:35:43 +0000 (06:35 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 15 Jan 2017 17:35:43 +0000 (06:35 +1300)
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

index 91ba5fee31353ea07a849b313192eebb0e0245ae..7c18b0b85515b5a03482fe8569b24ba6c4b2f0db 100644 (file)
@@ -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;