]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix old bug: append sometimes does not fully copy a string if \0 exists in source
authoramosjeffries <>
Sat, 19 May 2007 20:51:14 +0000 (20:51 +0000)
committeramosjeffries <>
Sat, 19 May 2007 20:51:14 +0000 (20:51 +0000)
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.

src/SqString.cc

index 120284252809dca8d824b35d5b0a3a4105ff86f0..8f0caf3eb2a822401443c3f2729649d734e42b03 100644 (file)
@@ -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;