From a91cf2c6dd95af8bab7d58f362d732b80d4ba9db Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 8 Apr 2008 08:55:01 +0000 Subject: Relevant BUGIDs: Purpose of commit: bugfix Commit summary: --------------- 2008-04-08 Tomas Mraz * libpam/pam_item.c (TRY_SET): Do not set when destination is identical to source. (pam_set_item): Do not overwrite destination when it is identical to source. --- libpam/pam_item.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'libpam') diff --git a/libpam/pam_item.c b/libpam/pam_item.c index 724ea694..f3d794eb 100644 --- a/libpam/pam_item.c +++ b/libpam/pam_item.c @@ -11,13 +11,15 @@ #include #include -#define TRY_SET(X, Y) \ -{ \ - char *_TMP_ = _pam_strdup(Y); \ - if (_TMP_ == NULL && (Y) != NULL) \ - return PAM_BUF_ERR; \ - free(X); \ - (X) = _TMP_; \ +#define TRY_SET(X, Y) \ +{ \ + if ((X) != (Y)) { \ + char *_TMP_ = _pam_strdup(Y); \ + if (_TMP_ == NULL && (Y) != NULL) \ + return PAM_BUF_ERR; \ + free(X); \ + (X) = _TMP_; \ + } \ } /* functions */ @@ -76,8 +78,10 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) * modules. */ if (__PAM_FROM_MODULE(pamh)) { - _pam_overwrite(pamh->authtok); - TRY_SET(pamh->authtok, item); + if (pamh->authtok != item) { + _pam_overwrite(pamh->authtok); + TRY_SET(pamh->authtok, item); + } } else { retval = PAM_BAD_ITEM; } @@ -90,8 +94,10 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) * modules. */ if (__PAM_FROM_MODULE(pamh)) { - _pam_overwrite(pamh->oldauthtok); - TRY_SET(pamh->oldauthtok, item); + if (pamh->oldauthtok != item) { + _pam_overwrite(pamh->oldauthtok); + TRY_SET(pamh->oldauthtok, item); + } } else { retval = PAM_BAD_ITEM; } @@ -130,6 +136,8 @@ int pam_set_item (pam_handle_t *pamh, int item_type, const void *item) break; case PAM_XAUTHDATA: + if (&pamh->xauth == item) + break; if (pamh->xauth.namelen) { _pam_overwrite(pamh->xauth.name); free(pamh->xauth.name); -- cgit v1.2.3