From d098bf854cae9c011f9c3b070adc918d2cd06158 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 29 Jul 2004 01:50:02 +0000 Subject: [PATCH] * set_ccache.c (gss_krb5_ccache_name): Don't make a copy of the string returned by kg_get_ccache_name. Simplify some calls using a temporary error code variable. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16629 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/gssapi/krb5/ChangeLog | 4 ++++ src/lib/gssapi/krb5/set_ccache.c | 38 ++++++++------------------------ 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/lib/gssapi/krb5/ChangeLog b/src/lib/gssapi/krb5/ChangeLog index c5f78eb3f..4bc52f823 100644 --- a/src/lib/gssapi/krb5/ChangeLog +++ b/src/lib/gssapi/krb5/ChangeLog @@ -1,5 +1,9 @@ 2004-07-28 Ken Raeburn + * set_ccache.c (gss_krb5_ccache_name): Don't make a copy of the + string returned by kg_get_ccache_name. Simplify some calls using + a temporary error code variable. + * gssapi_krb5.c (kg_get_ccache_name): Make a copy of the default ccache name, because calling krb5_free_context will destroy it. Make the copy always, not just in the local-context case. Check diff --git a/src/lib/gssapi/krb5/set_ccache.c b/src/lib/gssapi/krb5/set_ccache.c index 27422017b..810c7a050 100644 --- a/src/lib/gssapi/krb5/set_ccache.c +++ b/src/lib/gssapi/krb5/set_ccache.c @@ -39,7 +39,6 @@ gss_krb5_ccache_name(minor_status, name, out_name) char *old_name = NULL; OM_uint32 err = 0; OM_uint32 minor = 0; - char *gss_out_name; err = gssint_initialize_library(); @@ -54,46 +53,27 @@ gss_krb5_ccache_name(minor_status, name, out_name) const char *tmp_name = NULL; if (!err) { - if (GSS_ERROR(kg_get_ccache_name (&minor, &tmp_name))) { - err = minor; - } - } - - if (!err) { - old_name = malloc(strlen(tmp_name) + 1); - if (old_name == NULL) { - err = ENOMEM; - } else { - strcpy(old_name, tmp_name); - } + kg_get_ccache_name (&err, &tmp_name); } - if (!err) { - char *swap = NULL; - - swap = gss_out_name; - gss_out_name = old_name; - old_name = swap; + old_name = gss_out_name; + gss_out_name = tmp_name; } } - - if (!err) { - if (GSS_ERROR(kg_set_ccache_name (&minor, name))) { - err = minor; - } - } + /* If out_name was NULL, we keep the same gss_out_name value, and + don't free up any storage (leave old_name NULL). */ + + if (!err) + kg_set_ccache_name (&err, name); minor = k5_setspecific(K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME, gss_out_name); if (minor) { /* Um. Now what? */ if (err == 0) { err = minor; - if (out_name != NULL) { - *out_name = NULL; - out_name = NULL; - } } free(gss_out_name); + gss_out_name = NULL; } if (!err) { -- 2.26.2