]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Close three possible buffer over/under-runs
authoramosjeffries <>
Mon, 5 Nov 2007 06:59:51 +0000 (06:59 +0000)
committeramosjeffries <>
Mon, 5 Nov 2007 06:59:51 +0000 (06:59 +0000)
Simple fixes imported from earlier string work.
 - prevent pointer operations in cut /set operations if the location
   given is outside teh currently allocated buffer.
The methods will behave as if the operations were successful but did
not alter the string.

src/SquidString.h
src/String.cci

index 4d97f35f96a4cbb151062b82efed41f6e0de06a5..c2f371d2b2eaeade77b0772686782007ccb77e50 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: SquidString.h,v 1.11 2007/09/28 01:40:50 amosjeffries Exp $
+ * $Id: SquidString.h,v 1.12 2007/11/04 23:59:51 amosjeffries Exp $
  *
  * DEBUG: section 67    String
  * AUTHOR: Duane Wessels
@@ -112,12 +112,11 @@ public:
     _SQUID_INLINE_ int caseCmp (char const *) const;
     _SQUID_INLINE_ int caseCmp (char const *, size_t count) const;
 
-    _SQUID_INLINE_ void set
-        (char const *loc, char const ch);
+    _SQUID_INLINE_ void set(char const *loc, char const ch);
 
-    _SQUID_INLINE_ void cut (size_t newLength);
+    _SQUID_INLINE_ void cut(size_t newLength);
 
-    _SQUID_INLINE_ void cutPointer (char const *loc);
+    _SQUID_INLINE_ void cutPointer(char const *loc);
 
 #if DEBUGSTRINGS
 
index e1995e46bc6e4eb1d18a73748fd1607e0d617f1d..ccc48f4ac0b076ed7634b5bc2b9499b712393bd1 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: String.cci,v 1.9 2007/05/29 13:31:38 amosjeffries Exp $
+ * $Id: String.cci,v 1.10 2007/11/04 23:59:52 amosjeffries Exp $
  *
  * DEBUG: section 67    String
  * AUTHOR: Duane Wessels
@@ -125,36 +125,39 @@ String::cmp (String const &aString) const
 }
 
 int
-String::caseCmp (char const *aString) const
+String::caseCmp(char const *aString) const
 {
     return strcasecmp(buf(), aString);
 }
 
 int
-String::caseCmp (char const *aString, size_t count) const
+String::caseCmp(char const *aString, size_t count) const
 {
     return strncasecmp(buf(), aString, count);
 }
 
-/* FIXME: this is can perform buffer overflows and underflows! */
 void
-String::set (char const *loc, char const ch)
+String::set(char const *loc, char const ch)
 {
+    if(loc < buf_ || loc > (buf_ + size_) ) return;
+
     buf_[loc-buf_] = ch;
 }
 
-/* FIXME: this is can perform buffer overflows and underflows! */
 void
-String::cut (size_t newLength)
+String::cut(size_t newLength)
 {
+    if(newLength < 0 || newLength > len_) return;
+
     len_ = newLength;
     buf_[newLength] = '\0';
 }
 
-/* FIXME: this is can perform buffer overflows and underflows! */
 void
-String::cutPointer (char const *loc)
+String::cutPointer(char const *loc)
 {
+    if(loc < buf_ || loc > (buf_ + size_) ) return;
+
     len_ = loc-buf_;
     buf_[len_] = '\0';
 }
@@ -165,5 +168,3 @@ operator<<(std::ostream& os, String const &aString)
     os << aString.buf();
     return os;
 }
-
-