krb5_parse_name not thread-safe, not responsive to environment changes
authorKen Raeburn <raeburn@mit.edu>
Mon, 3 Jan 2005 19:30:18 +0000 (19:30 +0000)
committerKen Raeburn <raeburn@mit.edu>
Mon, 3 Jan 2005 19:30:18 +0000 (19:30 +0000)
As Ezra noted, krb5_parse_name saves away the default realm the first
time it looks it up, and will never look it up again, even if the
config file has changed, the context isn't the same one, etc.  It also
used a static variable which wasn't thread-safe.

With this patch, we still won't catch changes in the config file
specification after the default realm has been looked up for a given
krb5_context, because it's cached in the context too, but this will at
least be more responsive, and thread safe.

* parse.c (krb5_parse_name): Don't cache the default realm name.

ticket: new
target_version: 1.4
tags: pullup

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16988 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/ChangeLog
src/lib/krb5/krb/parse.c

index 46483aca3494406419307c582d0ee9f848622f58..4b01bfcb83b5a4a875a66e8b6acfa9cbacc2290a 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-03  Ken Raeburn  <raeburn@mit.edu>
+
+       * parse.c (krb5_parse_name): Don't cache the default realm name.
+
 2004-10-26  Tom Yu  <tlyu@mit.edu>
 
        * mk_req_ext.c (krb5_mk_req_extended): Free keyblock before
index 50f7b225bd117ac04d0d4bfce1ae4727897982e0..cd23d14d1701ec9da4cd45d6340f398ddfb0c5d3 100644 (file)
@@ -73,8 +73,8 @@ krb5_parse_name(krb5_context context, const char *name, krb5_principal *nprincip
        const char      *parsed_realm = NULL;
        int             fcompsize[FCOMPNUM];
        unsigned int    realmsize = 0;
-       static char     *default_realm = NULL;
-       static int      default_realm_size = 0;
+       char            *default_realm = NULL;
+       int             default_realm_size = 0;
        char            *tmpdata;
        krb5_principal  principal;
        krb5_error_code retval;
@@ -211,6 +211,7 @@ krb5_parse_name(krb5_context context, const char *name, krb5_principal *nprincip
        if (tmpdata == 0) {
                krb5_xfree(principal->data);
                krb5_xfree(principal);
+               krb5_xfree(default_realm);
                return ENOMEM;
        }
        krb5_princ_set_realm_length(context, principal, realmsize);
@@ -224,6 +225,7 @@ krb5_parse_name(krb5_context context, const char *name, krb5_principal *nprincip
                        krb5_xfree(krb5_princ_realm(context, principal)->data);
                        krb5_xfree(principal->data);
                        krb5_xfree(principal);
+                       krb5_xfree(default_realm);
                        return(ENOMEM);
                }
                krb5_princ_component(context, principal, i)->data = tmpdata2;
@@ -276,6 +278,7 @@ krb5_parse_name(krb5_context context, const char *name, krb5_principal *nprincip
        principal->magic = KV5M_PRINCIPAL;
        principal->realm.magic = KV5M_DATA;
        *nprincipal = principal;
+       krb5_xfree(default_realm);
        return(0);
 }