From: amosjeffries <> Date: Sat, 19 May 2007 20:51:14 +0000 (+0000) Subject: Fix old bug: append sometimes does not fully copy a string if \0 exists in source X-Git-Tag: SQUID_3_0_PRE7~253 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96958a782fd397db17a9cb3d5a8d10185113104c;p=thirdparty%2Fsquid.git Fix old bug: append sometimes does not fully copy a string if \0 exists in source This bug exists in the basic implementation of strncat(dst,src,len) which will only copy EITHER to len or first \0 character, whichever comes first. In squid this only occurs only if the string internal buffer is large enough to hold the existing plus the new strings. The buffer re-allocation code used proper xmemcpy which does not have this limitation. Have now set both append() branches to use the same copy mechanism. --- diff --git a/src/SqString.cc b/src/SqString.cc index 1202842528..8f0caf3eb2 100644 --- a/src/SqString.cc +++ b/src/SqString.cc @@ -1,6 +1,6 @@ /* - * $Id: SqString.cc,v 1.3 2007/05/19 06:31:00 amosjeffries Exp $ + * $Id: SqString.cc,v 1.4 2007/05/19 14:51:14 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -186,7 +186,8 @@ SqString::append(const char *str, int len) return; if (len_ + len < size_) { - strncat(buf_, str, len); + operator[](len_+len) = '\0'; + xmemcpy(buf_+len_, str, len); len_ += len; } else { unsigned int ssz = len_ + len;