]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4227: invalid key in AuthUserHashPointer causing assertation failure
authorManuel Meitinger <m.meitinger@aufbauwerk.com>
Tue, 7 Jul 2015 08:42:54 +0000 (01:42 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 7 Jul 2015 08:42:54 +0000 (01:42 -0700)
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.

src/auth/User.cc
src/auth/User.h

index 8ebe56ecdc4fccd826e0673f87738339e49408aa..71e5fce67e1d356ed023e838db08422ac0766ff3 100644 (file)
@@ -31,8 +31,9 @@ Auth::User::User(Auth::Config *aConfig, const char *aRequestRealm) :
     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 @@ Auth::User::~User()
 
     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 @@ Auth::User::UsernameCacheStats(StoreEntry *output)
 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_)
     }
 }
 
index 6af51cad1614b68f5d227f46d12fbdad17843a2e..d7dc67f38142c1100c52bb20815c75a11be5d607 100644 (file)
@@ -66,7 +66,7 @@ public:
     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 @@ private:
     /**
      * 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;