From 4c2925d2aa0b7256b53eb61ef072c4685f728bd2 Mon Sep 17 00:00:00 2001 From: Robbie Harwood Date: Tue, 27 Sep 2016 20:50:59 +0000 Subject: Fix two leaks in gp_get_cred_environment() Signed-off-by: Robbie Harwood Reviewed-by: Simo Sorce --- proxy/src/gp_creds.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'proxy') diff --git a/proxy/src/gp_creds.c b/proxy/src/gp_creds.c index 446c7d8..8280ef2 100644 --- a/proxy/src/gp_creds.c +++ b/proxy/src/gp_creds.c @@ -248,7 +248,7 @@ static int gp_get_cred_environment(struct gp_call_ctx *gpcall, int ret = -1; int k_num = -1; int ck_num = -1; - int c, d; + int d; memset(cs, 0, sizeof(gss_key_value_set_desc)); @@ -354,7 +354,6 @@ static int gp_get_cred_environment(struct gp_call_ctx *gpcall, ret = ENOMEM; goto done; } - c = 0; for (d = 0; d < svc->krb5.cred_count; d++) { p = strchr(svc->krb5.cred_store[d], ':'); if (!p) { @@ -366,9 +365,9 @@ static int gp_get_cred_environment(struct gp_call_ctx *gpcall, } if (strncmp(svc->krb5.cred_store[d], "client_keytab:", 14) == 0) { - ck_num = c; + ck_num = cs->count; } else if (strncmp(svc->krb5.cred_store[d], "keytab:", 7) == 0) { - k_num = c; + k_num = cs->count; } ret = asprintf(&str, "%.*s", (int)(p - svc->krb5.cred_store[d]), @@ -377,19 +376,20 @@ static int gp_get_cred_environment(struct gp_call_ctx *gpcall, ret = ENOMEM; goto done; } - cs->elements[c].key = str; + cs->elements[cs->count].key = str; fmtstr = p + 1; - cs->elements[c].value = get_formatted_string(fmtstr, target_uid); - if (!cs->elements[c].value) { + cs->elements[cs->count].value = + get_formatted_string(fmtstr, target_uid); + if (!cs->elements[cs->count].value) { + safefree(str); GPDEBUG("Failed to build credential store formatted string.\n"); ret = ENOMEM; goto done; } - c++; + cs->count++; } - cs->count = c; /* when a user is not explicitly requested then it means the calling * application wants to use the credentials in the standard keytab, -- cgit