From 3f5f1a0170e2be74f12247a1c65f495cf5235102 Mon Sep 17 00:00:00 2001 From: wessels <> Date: Wed, 9 May 2007 14:26:57 +0000 Subject: [PATCH] Fixed free() errors in AuthUser::~AuthUser() AuthUser::~AuthUser() was freeing memory in the middle of an allocated buffer. I think AuthUser needs a strdup'd copy of the username, rather than keeping a pointer to the buffer read from the helper. Also I found 'xfree((char *)username());' really odd. This username() method does not return a reference so it shouldn't be used as LHS in the macro. --- src/AuthUser.cc | 6 +++--- src/AuthUser.cci | 4 ++-- src/AuthUser.h | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/AuthUser.cc b/src/AuthUser.cc index c266ee7c13..3b829e158f 100644 --- a/src/AuthUser.cc +++ b/src/AuthUser.cc @@ -1,6 +1,6 @@ /* - * $Id: AuthUser.cc,v 1.6 2007/05/09 07:36:24 wessels Exp $ + * $Id: AuthUser.cc,v 1.7 2007/05/09 08:26:57 wessels Exp $ * * DEBUG: section 29 Authenticator * AUTHOR: Robert Collins @@ -130,8 +130,8 @@ AuthUser::~AuthUser() /* free seen ip address's */ clearIp(); - if (username()) - xfree((char *)username()); + if (username_) + xfree((char*)username_); /* prevent accidental reuse */ auth_type = AUTH_UNKNOWN; diff --git a/src/AuthUser.cci b/src/AuthUser.cci index d6c754d05b..53e89b38e8 100644 --- a/src/AuthUser.cci +++ b/src/AuthUser.cci @@ -1,6 +1,6 @@ /* - * $Id: AuthUser.cci,v 1.1 2004/08/30 03:28:56 robertc Exp $ + * $Id: AuthUser.cci,v 1.2 2007/05/09 08:26:57 wessels Exp $ * * DEBUG: section 29 Authenticator * AUTHOR: Robert Collins @@ -44,7 +44,7 @@ void AuthUser::username(char const*aString) { assert (!username() || !aString); - username_ = aString; + username_ = xstrdup(aString); } void diff --git a/src/AuthUser.h b/src/AuthUser.h index db6dff02b9..8fa993625b 100644 --- a/src/AuthUser.h +++ b/src/AuthUser.h @@ -1,6 +1,6 @@ /* - * $Id: AuthUser.h,v 1.4 2007/05/09 07:45:58 wessels Exp $ + * $Id: AuthUser.h,v 1.5 2007/05/09 08:26:57 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -87,6 +87,11 @@ protected: private: static void cacheCleanup (void *unused); + /* + * DPW 2007-05-08 + * The username_ memory will be allocated via + * xstrdup(). It is our responsibility. + */ char const *username_; /* what ip addresses has this user been seen at?, plus a list length cache */ -- 2.47.3