From: Amos Jeffries Date: Sun, 8 Feb 2015 11:40:30 +0000 (-0800) Subject: Bug 4176: Digest auth too many helper lookups X-Git-Tag: merge-candidate-3-v1~276 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=0203ae29639d7be6eae2a316131174019c6fcfee;p=thirdparty%2Fsquid.git Bug 4176: Digest auth too many helper lookups --- diff --git a/src/auth/User.cc b/src/auth/User.cc index e90a1ea92a..4808099372 100644 --- a/src/auth/User.cc +++ b/src/auth/User.cc @@ -309,7 +309,10 @@ SBuf Auth::User::BuildUserKey(const char *username, const char *realm) { SBuf key; - key.Printf("%s:%s", username, realm); + if (realm) + key.Printf("%s:%s", username, realm); + else + key.append(username, strlen(username)); return key; } @@ -365,10 +368,11 @@ Auth::User::username(char const *aString) if (aString) { assert(!username_); username_ = xstrdup(aString); - if (!requestRealm_.isEmpty()) - userKey_ = BuildUserKey(username_, requestRealm_.c_str()); + // NP: param #2 is working around a c_str() data-copy performance regression + userKey_ = BuildUserKey(username_, (!requestRealm_.isEmpty() ? requestRealm_.c_str() : NULL)); } else { safe_free(username_); + userKey_.clear(); } } diff --git a/src/auth/User.h b/src/auth/User.h index 7ecdb2e90b..6af51cad16 100644 --- a/src/auth/User.h +++ b/src/auth/User.h @@ -63,9 +63,10 @@ public: void absorb(Auth::User::Pointer from); virtual ~User(); char const *username() const { return username_; } - void username(char const *); + void username(char const *); ///< set stored username and userKey - const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : username_;} + // 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;} /** * How long these credentials are still valid for.