--------------------- PatchSet 6551 Date: 2008/01/19 12:11:22 Author: amosjeffries Branch: ayjwork Tag: (none) Log: Convert FTP usage of URI from String-pointer to String-offset - Removes two unnecessary raw-buffer access - Adds roffset(char) function to eventually replace rpos(char) - Resurrects unused cut(offset) with an additional test to prevent possible buffer-overwrite on zero-length strings. Members: src/SquidString.h:1.8.8.13->1.8.8.14 src/String.cci:1.6.6.6->1.6.6.7 src/ftp.cc:1.62.4.15->1.62.4.16 Index: squid3/src/SquidString.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/SquidString.h,v retrieving revision 1.8.8.13 retrieving revision 1.8.8.14 diff -u -r1.8.8.13 -r1.8.8.14 --- squid3/src/SquidString.h 19 Jan 2008 11:35:23 -0000 1.8.8.13 +++ squid3/src/SquidString.h 19 Jan 2008 12:11:22 -0000 1.8.8.14 @@ -1,5 +1,5 @@ /* - * $Id: SquidString.h,v 1.8.8.13 2008/01/19 11:35:23 amosjeffries Exp $ + * $Id: SquidString.h,v 1.8.8.14 2008/01/19 12:11:22 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -118,9 +118,9 @@ \retval N Positive offset of the character in the string. \retval -N Negative value if Character not found. */ - _SQUID_INLINE_ const int rpos(char const ch) const; + _SQUID_INLINE_ const int roffset(char const ch) const; - /** \deprecated Should be using the offset-lookup instead: unsigned int rpos(char) + /** \deprecated Should be using the roffset(char) instead. */ _SQUID_INLINE_ const char * rpos(char const ch) const; @@ -135,12 +135,16 @@ */ _SQUID_INLINE_ void set(char const *loc, char const ch); -#if 0 - /** \deprecated Use assignment to [] position instead. - * ie str[newLength] = '\0'; + /** + * Cut a string objects content down to a set length. + * Does not physically affect the buffer size, just alters its length state. + * Cuts longer than the existing length or less than zero are silently ignored. + \par NP: + * For now it will null-terminate the string. This may change. + * + \param newLength New Length of string buffer. */ _SQUID_INLINE_ void cut(size_t newLength); -#endif /** \deprecated Use assignment to [] position instead. * ie str[newLength] = '\0'; Index: squid3/src/String.cci =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/String.cci,v retrieving revision 1.6.6.6 retrieving revision 1.6.6.7 diff -u -r1.6.6.6 -r1.6.6.7 --- squid3/src/String.cci 19 Jan 2008 11:35:23 -0000 1.6.6.6 +++ squid3/src/String.cci 19 Jan 2008 12:11:22 -0000 1.6.6.7 @@ -1,5 +1,5 @@ /* - * $Id: String.cci,v 1.6.6.6 2008/01/19 11:35:23 amosjeffries Exp $ + * $Id: String.cci,v 1.6.6.7 2008/01/19 12:11:22 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -72,11 +72,11 @@ } const int -String::rpos(char const ch) const +String::roffset(char const ch) const { - unsigned int r = _len; - if(_len == 0) return -1; - while(r > 0 && _buf[r] != ch) --r; + unsigned int r = len_; + if(len_ == 0) return -1; + while(r > 0 && buf_[r] != ch) --r; return r; } @@ -160,16 +160,16 @@ buf_[loc-buf_] = ch; } -#if DEAD_CODE void 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'; } -#endif void String::cutPointer(char const *loc) Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.62.4.15 retrieving revision 1.62.4.16 diff -u -r1.62.4.15 -r1.62.4.16 --- squid3/src/ftp.cc 19 Jan 2008 08:53:22 -0000 1.62.4.15 +++ squid3/src/ftp.cc 19 Jan 2008 12:11:22 -0000 1.62.4.16 @@ -1,5 +1,5 @@ /* - * $Id: ftp.cc,v 1.62.4.15 2008/01/19 08:53:22 amosjeffries Exp $ + * $Id: ftp.cc,v 1.62.4.16 2008/01/19 12:11:22 amosjeffries Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -1423,13 +1423,12 @@ void FtpStateData::checkUrlpath() { - int l; - const char *t; + int l, t; - if ((t = request->urlpath.rpos(';')) != NULL) { - if (strncasecmp(t + 1, "type=", 5) == 0) { - typecode = (char) xtoupper(*(t + 6)); - request->urlpath.cutPointer(t); + if ((t = request->urlpath.roffset(';')) >= 0) { + if (strncasecmp( &(request->urlpath[t+1]), "type=", 5) == 0) { + typecode = (char) xtoupper( request->urlpath[t+6] ); + request->urlpath.cut(t); } } @@ -1444,7 +1443,7 @@ /* UNIX root directory */ flags.isdir = 1; flags.root_dir = 1; - } else if ((l >= 1) && (*(request->urlpath.buf() + l - 1) == '/')) { + } else if ((l >= 1) && request->urlpath[l-1] == '/') { /* Directory URL, ending in / */ flags.isdir = 1;