public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Alice Mitchell <ajmitchell@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: steved@redhat.com, Alice Mitchell <ajmitchell@redhat.com>
Subject: [PATCH 3/4 v2] nfs-utils: Fix mem leaks in krb5_util
Date: Thu, 12 Aug 2021 19:13:18 +0100	[thread overview]
Message-ID: <20210812181319.3885781-4-ajmitchell@redhat.com> (raw)
In-Reply-To: <20210812181319.3885781-1-ajmitchell@redhat.com>

query_krb5_ccache: if the ret_realm strdup fails then ret_princname leaks

gssd_get_krb5_machine_cred_list: l was being leaked if the realloc failed
it was also leaked if the strdup of ccname failed

Signed-off-by: Alice Mitchell <ajmitchell@redhat.com>
---
 utils/gssd/krb5_util.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
index c5f1152..6d059f3 100644
--- a/utils/gssd/krb5_util.c
+++ b/utils/gssd/krb5_util.c
@@ -1129,6 +1129,12 @@ query_krb5_ccache(const char* cred_cache, char **ret_princname,
 			    *str = '\0';
 			    *ret_princname = strdup(princstring);
 			    *ret_realm = strdup(str+1);
+			    if (!*ret_princname || !*ret_realm) {
+				    free(*ret_princname);
+				    free(*ret_realm);
+				    *ret_princname = NULL;
+				    *ret_realm = NULL;
+			    }
 		    }
 		    k5_free_unparsed_name(context, princstring);
 		}
@@ -1350,15 +1356,19 @@ gssd_get_krb5_machine_cred_list(char ***list)
 		if (retval)
 			continue;
 		if (i + 1 > listsize) {
+			char **tmplist;
 			listsize += listinc;
-			l = (char **)
+			tmplist = (char **)
 				realloc(l, listsize * sizeof(char *));
-			if (l == NULL) {
+			if (tmplist == NULL) {
+				gssd_free_krb5_machine_cred_list(l);
 				retval = ENOMEM;
 				goto out_lock;
 			}
+			l = tmplist;
 		}
 		if ((l[i++] = strdup(ple->ccname)) == NULL) {
+			gssd_free_krb5_machine_cred_list(l);
 			retval = ENOMEM;
 			goto out_lock;
 		}
-- 
2.27.0


  parent reply	other threads:[~2021-08-12 18:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 18:13 [PATCH 0/4 v2] nfs-utils: A series of memory fixes Alice Mitchell
2021-08-12 18:13 ` [PATCH 1/4 v2] nfs-utils: Fix potential memory leaks in idmap Alice Mitchell
2021-08-12 18:13 ` [PATCH 2/4 v2] nfs-utils: Fix mem leaks in gssd Alice Mitchell
2021-08-12 18:13 ` Alice Mitchell [this message]
2021-08-12 18:13 ` [PATCH 4/4 v2] nfs-utils: Fix mem leak in mountd Alice Mitchell
2021-08-26 19:21 ` [PATCH 0/4 v2] nfs-utils: A series of memory fixes Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210812181319.3885781-4-ajmitchell@redhat.com \
    --to=ajmitchell@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox