------------------------------------------------------------ revno: 13859 revision-id: squid3@treenet.co.nz-20150707084254-5o2dmaumckmtqzab parent: squid3@treenet.co.nz-20150703091109-f5ochym00ynzfmkg fixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=4227 author: Manuel Meitinger committer: Amos Jeffries branch nick: 3.5 timestamp: Tue 2015-07-07 01:42:54 -0700 message: Bug 4227: invalid key in AuthUserHashPointer causing assertation failure Temporary workaroudn patch, reverting SBuf conversion of AuthUser key data storage. NOTE: This patch is applied to 3.5 series only. Squid-4 series and later are not yet fixed. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20150707084254-5o2dmaumckmtqzab # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: 451110d5ed39736557b34b8672372fad06a4aad6 # timestamp: 2015-07-07 08:50:54 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20150703091109-\ # f5ochym00ynzfmkg # # Begin patch === modified file 'src/auth/User.cc' --- src/auth/User.cc 2015-02-10 04:52:44 +0000 +++ src/auth/User.cc 2015-07-07 08:42:54 +0000 @@ -31,8 +31,9 @@ notes(), credentials_state(Auth::Unchecked), username_(NULL), - requestRealm_(aRequestRealm) + userKey_(NULL) { + requestRealm_ = aRequestRealm ? xstrdup(aRequestRealm) : NULL; proxy_match_cache.head = proxy_match_cache.tail = NULL; ip_list.head = ip_list.tail = NULL; debugs(29, 5, HERE << "Initialised auth_user '" << this << "'."); @@ -134,6 +135,10 @@ if (username_) xfree((char*)username_); + if (requestRealm_) + xfree((char*)requestRealm_); + if (userKey_) + xfree((char*)userKey_); /* prevent accidental reuse */ auth_type = Auth::AUTH_UNKNOWN; @@ -365,14 +370,17 @@ void Auth::User::username(char const *aString) { + SBuf key; + if (aString) { assert(!username_); username_ = xstrdup(aString); - // NP: param #2 is working around a c_str() data-copy performance regression - userKey_ = BuildUserKey(username_, (!requestRealm_.isEmpty() ? requestRealm_.c_str() : NULL)); + key = BuildUserKey(username_, requestRealm_); + // XXX; performance regression. c_str() reallocates, then xstrdup() reallocates + userKey_ = xstrdup(key.c_str()); } else { safe_free(username_); - userKey_.clear(); + safe_free(userKey_) } } === modified file 'src/auth/User.h' --- src/auth/User.h 2015-02-10 04:52:44 +0000 +++ src/auth/User.h 2015-07-07 08:42:54 +0000 @@ -66,7 +66,7 @@ void username(char const *); ///< set stored username and userKey // NP: key is set at the same time as username_. Until then both are empty/NULL. - const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : NULL;} + const char *userKey() {return userKey_;} /** * How long these credentials are still valid for. @@ -116,13 +116,17 @@ /** * A realm for the user depending on request, designed to identify users, * with the same username and different authentication domains. + * The requestRealm_ memory will be allocated via xstrdup(). + * It is our responsibility. */ - SBuf requestRealm_; + const char *requestRealm_; /** - * A Unique key for the user, consist by username and requestRealm_ + * A Unique key for the user, consist by username and realm. + * The userKey_ memory will be allocated via xstrdup(). + * It is our responsibility. */ - SBuf userKey_; + const char *userKey_; /** what ip addresses has this user been seen at?, plus a list length cache */ dlink_list ip_list;