From: Francesco Chemolli Date: Tue, 10 Feb 2009 11:02:53 +0000 (+0100) Subject: Converted more unsafeBuf users. X-Git-Tag: SQUID_3_2_0_1~1189^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7a42b149d312840bed63e2c353a51837241aeeb;p=thirdparty%2Fsquid.git Converted more unsafeBuf users. --- diff --git a/src/ACLExtUser.cc b/src/ACLExtUser.cc index bbdbb08df0..54be55173d 100644 --- a/src/ACLExtUser.cc +++ b/src/ACLExtUser.cc @@ -79,7 +79,7 @@ int ACLExtUser::match(ACLChecklist *checklist) { if (checklist->request->extacl_user.size()) { - return data->match(checklist->request->extacl_user.unsafeBuf()); + return data->match(checklist->request->extacl_user.termedBuf()); } else { return -1; } diff --git a/src/DiskIO/AIO/AIODiskFile.cc b/src/DiskIO/AIO/AIODiskFile.cc index fd31fc1a17..1a2c801366 100644 --- a/src/DiskIO/AIO/AIODiskFile.cc +++ b/src/DiskIO/AIO/AIODiskFile.cc @@ -87,10 +87,9 @@ AIODiskFile::open(int flags, mode_t mode, RefCount callback) { /* Simulate async calls */ #ifdef _SQUID_WIN32_ - fd = aio_open(path.unsafeBuf(), flags); + fd = aio_open(path.termedBuf(), flags); #else - - fd = file_open(path.unsafeBuf() , flags); + fd = file_open(path.termedBuf() , flags); #endif ioRequestor = callback; diff --git a/src/ESICustomParser.cc b/src/ESICustomParser.cc index 8a5ce83816..b59880d009 100644 --- a/src/ESICustomParser.cc +++ b/src/ESICustomParser.cc @@ -109,7 +109,8 @@ ESICustomParser::parse(char const *dataToParse, size_t const lengthOfData, bool } size_t openESITags (0); - char const *currentPos = content.unsafeBuf(); + //erring on the safe side. Probably rawBuf would be ok too + char const *currentPos = content.termedBuf(); size_t remainingCount = content.size(); char const *tag = NULL; @@ -302,7 +303,7 @@ char const * ESICustomParser::errorString() const { if (error.size()) - return error.unsafeBuf(); + return error.termedBuf(); else return "Parsing error strings not implemented"; } diff --git a/src/ICAP/ICAPServiceRep.cc b/src/ICAP/ICAPServiceRep.cc index 5bc39d8c2b..bd743c0996 100644 --- a/src/ICAP/ICAPServiceRep.cc +++ b/src/ICAP/ICAPServiceRep.cc @@ -279,7 +279,7 @@ void ICAPServiceRep::checkOptions() if (!method_found) { debugs(93,1, "WARNING: Squid is configured to use ICAP method " << cfg().methodStr() << - " for service " << cfg().uri.unsafeBuf() << + " for service " << cfg().uri << " but OPTIONS response declares the methods are " << method_list); } } @@ -293,7 +293,7 @@ void ICAPServiceRep::checkOptions() // TODO: If skew is negative, the option will be considered down // because of stale options. We should probably change this. debugs(93, 1, "ICAP service's clock is skewed by " << skew << - " seconds: " << cfg().uri.unsafeBuf()); + " seconds: " << cfg().uri); } } diff --git a/src/ICAP/ICAPXaction.cc b/src/ICAP/ICAPXaction.cc index 45dce4ceb3..9bf529eddd 100644 --- a/src/ICAP/ICAPXaction.cc +++ b/src/ICAP/ICAPXaction.cc @@ -76,7 +76,7 @@ void ICAPXaction::openConnection() disableRetries(); // this will also safely drain pconn pool // TODO: check whether NULL domain is appropriate here - connection = icapPconnPool->pop(s.cfg().host.unsafeBuf(), s.cfg().port, NULL, client_addr, isRetriable); + connection = icapPconnPool->pop(s.cfg().host.termedBuf(), s.cfg().port, NULL, client_addr, isRetriable); if (connection >= 0) { debugs(93,3, HERE << "reused pconn FD " << connection); @@ -96,12 +96,12 @@ void ICAPXaction::openConnection() IpAddress outgoing; connection = comm_open(SOCK_STREAM, 0, outgoing, - COMM_NONBLOCKING, s.cfg().uri.unsafeBuf()); + COMM_NONBLOCKING, s.cfg().uri.termedBuf()); if (connection < 0) dieOnConnectionFailure(); // throws - debugs(93,3, typeName << " opens connection to " << s.cfg().host.unsafeBuf() << ":" << s.cfg().port); + debugs(93,3, typeName << " opens connection to " << s.cfg().host << ":" << s.cfg().port); // TODO: service bypass status may differ from that of a transaction typedef CommCbMemFunT TimeoutDialer; @@ -119,7 +119,7 @@ void ICAPXaction::openConnection() typedef CommCbMemFunT ConnectDialer; connector = asyncCall(93,3, "ICAPXaction::noteCommConnected", ConnectDialer(this, &ICAPXaction::noteCommConnected)); - commConnectStart(connection, s.cfg().host.unsafeBuf(), s.cfg().port, connector); + commConnectStart(connection, s.cfg().host.termedBuf(), s.cfg().port, connector); } /* @@ -157,7 +157,7 @@ void ICAPXaction::closeConnection() debugs(93,3, HERE << "pushing pconn" << status()); AsyncCall::Pointer call = NULL; commSetTimeout(connection, -1, call); - icapPconnPool->push(connection, theService->cfg().host.unsafeBuf(), + icapPconnPool->push(connection, theService->cfg().host.termedBuf(), theService->cfg().port, NULL, client_addr); disableRetries(); } else { @@ -232,7 +232,7 @@ void ICAPXaction::handleCommTimedout() { debugs(93, 2, HERE << typeName << " failed: timeout with " << theService->cfg().methodStr() << " " << - theService->cfg().uri.unsafeBuf() << status()); + theService->cfg().uri << status()); reuseConnection = false; service().noteFailure(); diff --git a/src/SquidString.h b/src/SquidString.h index a3ef838fd7..47e1194b21 100644 --- a/src/SquidString.h +++ b/src/SquidString.h @@ -88,6 +88,8 @@ public: String (String const &); ~String(); + typedef unsigned int size_type; //storage size intentionally unspecified + String &operator =(char const *); String &operator =(String const &); bool operator ==(String const &) const; @@ -99,7 +101,7 @@ public: */ _SQUID_INLINE_ char operator [](unsigned int pos) const; - _SQUID_INLINE_ size_t size() const; + _SQUID_INLINE_ size_type size() const; /// variant of size() suited to be used for printf-alikes. /// throws when size() > MAXINT _SQUID_INLINE_ int psize() const; @@ -135,22 +137,22 @@ public: _SQUID_INLINE_ const char * pos(char const ch) const; ///offset from string start of the first occurrence of ch /// returns std::string::npos if ch is not found - _SQUID_INLINE_ size_t find(char const ch) const; + _SQUID_INLINE_ size_type find(char const ch) const; _SQUID_INLINE_ const char * rpos(char const ch) const; - _SQUID_INLINE_ size_t rfind(char const ch) const; + _SQUID_INLINE_ size_type rfind(char const ch) const; _SQUID_INLINE_ int cmp (char const *) const; - _SQUID_INLINE_ int cmp (char const *, size_t count) const; + _SQUID_INLINE_ int cmp (char const *, size_type count) const; _SQUID_INLINE_ int cmp (String const &) const; _SQUID_INLINE_ int caseCmp (char const *) const; - _SQUID_INLINE_ int caseCmp (char const *, size_t count) const; + _SQUID_INLINE_ int caseCmp (char const *, size_type count) const; _SQUID_INLINE_ int caseCmp (String const &) const; - String substr(size_t from, size_t to) const; + String substr(size_type from, size_type to) const; /** \deprecated Use assignment to [] position instead. * ie str[newLength] = '\0'; */ - _SQUID_INLINE_ void cut(size_t newLength); + _SQUID_INLINE_ void cut(size_type newLength); #if DEBUGSTRINGS @@ -163,13 +165,13 @@ public: private: void allocAndFill(const char *str, int len); - void allocBuffer(size_t sz); - void setBuffer(char *buf, size_t sz); + void allocBuffer(size_type sz); + void setBuffer(char *buf, size_type sz); /* never reference these directly! */ - size_t size_; /* buffer size; 64K limit */ + size_type size_; /* buffer size; 64K limit */ - size_t len_; /* current length */ + size_type len_; /* current length */ char *buf_; diff --git a/src/String.cc b/src/String.cc index 1edb991119..bc129f14fa 100644 --- a/src/String.cc +++ b/src/String.cc @@ -39,7 +39,7 @@ // low-level buffer allocation, // does not free old buffer and does not adjust or look at len_ void -String::allocBuffer(size_t sz) +String::allocBuffer(String::size_type sz) { PROF_start(StringInitBuf); assert (undefined()); @@ -51,7 +51,7 @@ String::allocBuffer(size_t sz) // low-level buffer assignment // does not free old buffer and does not adjust or look at len_ void -String::setBuffer(char *aBuf, size_t aSize) +String::setBuffer(char *aBuf, String::size_type aSize) { assert(undefined()); assert(aSize < 65536); @@ -234,7 +234,7 @@ String::absorb(String &old) } String -String::substr(size_t from, size_t to) const +String::substr(String::size_type from, String::size_type to) const { Must(from >= 0 && from < size()); Must(to > 0 && to <= size()); @@ -292,7 +292,7 @@ StringRegistry::remove StringRegistry StringRegistry::Instance_; -extern size_t memStringCount(); +extern String::size_type memStringCount(); void StringRegistry::Stat(StoreEntry *entry) diff --git a/src/String.cci b/src/String.cci index a5fd17acd9..751086aa59 100644 --- a/src/String.cci +++ b/src/String.cci @@ -52,7 +52,7 @@ String::String() : size_(0), len_(0), buf_ (NULL) #endif } -size_t +String::size_type String::size() const { return len_; @@ -113,7 +113,7 @@ String::pos(char const ch) const return strchr(termedBuf(), ch); } -size_t +String::size_type String::find(char const ch) const { const char *c; @@ -129,7 +129,7 @@ String::rpos(char const ch) const return strrchr(termedBuf(), (ch)); } -size_t +String::size_type String::rfind(char const ch) const { const char *c; @@ -158,7 +158,7 @@ String::cmp (char const *aString) const } int -String::cmp (char const *aString, size_t count) const +String::cmp (char const *aString, String::size_type count) const { /* always the same at length 0 */ @@ -201,7 +201,7 @@ String::caseCmp(char const *aString) const } int -String::caseCmp(char const *aString, size_t count) const +String::caseCmp(char const *aString, String::size_type count) const { return strncasecmp(termedBuf(), aString, count); } @@ -222,7 +222,7 @@ String::set(char const *loc, char const ch) } void -String::cut(size_t newLength) +String::cut(String::size_type newLength) { if (newLength < 0 || newLength > len_) return; diff --git a/src/adaptation/Config.cc b/src/adaptation/Config.cc index ce1fb7c505..ac5f17ee23 100644 --- a/src/adaptation/Config.cc +++ b/src/adaptation/Config.cc @@ -141,7 +141,7 @@ Adaptation::Config::DumpServiceSet(StoreEntry *entry, const char *name) { typedef Groups::iterator GI; for (GI i = AllGroups().begin(); i != AllGroups().end(); ++i) - storeAppendPrintf(entry, "%s %s\n", name, (*i)->id.unsafeBuf()); + storeAppendPrintf(entry, "%s %.*s\n", name, (*i)->id.psize(), (*i)->id.rawBuf()); } void @@ -181,7 +181,7 @@ Adaptation::Config::DumpAccess(StoreEntry *entry, const char *name) typedef AccessRules::iterator CI; for (CI i = AllRules().begin(); i != AllRules().end(); ++i) { - snprintf(nom, 64, "%s %s", name, (*i)->groupId.unsafeBuf()); + snprintf(nom, 64, "%s %.*s", name, (*i)->groupId.psize(), (*i)->groupId.rawBuf()); dump_acl_access(entry, nom, (*i)->acl); } } diff --git a/src/client_side.cc b/src/client_side.cc index 021ecfd135..98d2924712 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1168,8 +1168,9 @@ ClientSocketContext::buildRangeHeader(HttpReply * rep) /* delete old Content-Type, add ours */ hdr->delById(HDR_CONTENT_TYPE); httpHeaderPutStrf(hdr, HDR_CONTENT_TYPE, - "multipart/byteranges; boundary=\"%s\"", - http->range_iter.boundary.unsafeBuf()); + "multipart/byteranges; boundary=\"%.*s\"", + http->range_iter.boundary.psize(), + http->range_iter.boundary.rawBuf()); /* Content-Length is not required in multipart responses * but it is always nice to have one */ actual_clen = http->mRangeCLen(); diff --git a/src/external_acl.cc b/src/external_acl.cc index 93b2534420..7adc8f610b 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -753,7 +753,7 @@ aclMatchExternal(external_acl_data *acl, ACLChecklist * ch) external_acl_cache_touch(acl->def, entry); result = entry->result; - external_acl_message = entry->message.unsafeBuf(); + external_acl_message = entry->message.termedBuf(); debugs(82, 2, "aclMatchExternal: " << acl->def->name << " = " << result); diff --git a/src/http.cc b/src/http.cc index 7a0a1a27ef..af9caa2ab5 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1808,7 +1808,7 @@ copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, co * pass on all other header fields * which are NOT listed by the special Connection: header. */ - if (strConnection.size()>0 && strListIsMember(&strConnection, e->name.unsafeBuf(), ',')) { + if (strConnection.size()>0 && strListIsMember(&strConnection, e->name.termedBuf(), ',')) { debugs(11, 2, "'" << e->name << "' header cropped by Connection: definition"); return; }