------------------------------------------------------------ revno: 14133 revision-id: squid3@treenet.co.nz-20170124201432-vskcudplmy2elpib parent: squid3@treenet.co.nz-20170123020546-zu7xmk0i006bq6cd author: Eduard Bagdasaryan committer: Amos Jeffries branch nick: 3.5 timestamp: Wed 2017-01-25 09:14:32 +1300 message: 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. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20170124201432-vskcudplmy2elpib # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: 7b9635a02d525d414145db09711d101ab7e87034 # timestamp: 2017-01-24 20:51:18 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20170123020546-\ # zu7xmk0i006bq6cd # # Begin patch === modified file 'src/format/Format.cc' --- src/format/Format.cc 2017-01-01 00:16:45 +0000 +++ src/format/Format.cc 2017-01-24 20:14:32 +0000 @@ -1297,6 +1297,11 @@ 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 @@ newout = (char *)xmalloc(out_len); newfree = 1; } else - newout = tmp; + newout = quotedOut; log_quoted_string(out, newout); } break;