From: amosjeffries <> Date: Tue, 12 Feb 2008 06:01:23 +0000 (+0000) Subject: Several String fixes. X-Git-Tag: BASIC_TPROXY4~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b270d4cecb480be29648d472ff70e8297a6ecc3;p=thirdparty%2Fsquid.git Several String fixes. - 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 --- diff --git a/src/SquidString.h b/src/SquidString.h index 4bb310b6a7..72eb4f8ce6 100644 --- a/src/SquidString.h +++ b/src/SquidString.h @@ -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 */ diff --git a/src/String.cci b/src/String.cci index fd726d9ba9..20adf5137a 100644 --- a/src/String.cci +++ b/src/String.cci @@ -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'; }