]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Several String fixes.
authoramosjeffries <>
Tue, 12 Feb 2008 06:01:23 +0000 (06:01 +0000)
committeramosjeffries <>
Tue, 12 Feb 2008 06:01:23 +0000 (06:01 +0000)
- Add two missing includes when configured --disable-inline
- SegFault when newly allocated string set to 0-length.
  buf_ may be NULL and buffer overruns on truncate attempt

src/SquidString.h
src/String.cci

index 4bb310b6a7dea327225d659b6fd00bb486d981d7..72eb4f8ce6b9a1e4bcf4ef221adcb79f92902ff2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: SquidString.h,v 1.15 2008/01/23 23:08:58 rousskov Exp $
+ * $Id: SquidString.h,v 1.16 2008/02/11 23:01:23 amosjeffries Exp $
  *
  * DEBUG: section 67    String
  * AUTHOR: Duane Wessels
@@ -35,6 +35,7 @@
 #ifndef SQUID_STRING_H
 #define SQUID_STRING_H
 
+#include "config.h"
 
 /* forward decls */
 
index fd726d9ba9e755959d72f8f55cfda05b3f5bcf0e..20adf5137a15f385a1c53becb23a80b213957321 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: String.cci,v 1.11 2008/01/19 10:38:32 amosjeffries Exp $
+ * $Id: String.cci,v 1.12 2008/02/11 23:01:23 amosjeffries Exp $
  *
  * DEBUG: section 67    String
  * AUTHOR: Duane Wessels
@@ -32,6 +32,8 @@
  *
  */
 
+#include "assert.h"
+
 String::String() : size_(0), len_(0), buf_ (NULL)
 {
 #if DEBUGSTRINGS
@@ -157,6 +159,8 @@ String::cut(size_t newLength)
     if(newLength < 0 || newLength > len_) return;
 
     len_ = newLength;
+
+    if(len_ == 0 && buf_ == NULL) return; // buf_ may be NULL on zero-length strings.
     buf_[newLength] = '\0';
 }