* g_cnffile.c (krb__get_srvtabname): Make retname be a static
authorTom Yu <tlyu@mit.edu>
Fri, 6 Jun 2003 14:44:33 +0000 (14:44 +0000)
committerTom Yu <tlyu@mit.edu>
Fri, 6 Jun 2003 14:44:33 +0000 (14:44 +0000)
array rather than a static pointer, to avoid callers' possible
retention of free()d pointers.  Yes, this may cause difficulty
with making this function thread-safe.

ticket: 1563
target_version: 1.3
version_fixed: 1.3
tags: pullup

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

src/lib/krb4/ChangeLog
src/lib/krb4/g_cnffile.c

index 2e6e0141c711fb79eb7d6bb27a67dac6bc004568..d779412b570a7706dd8e96e4a8424fd3ed89e5ae 100644 (file)
@@ -1,3 +1,10 @@
+2003-06-06  Tom Yu  <tlyu@mit.edu>
+
+       * g_cnffile.c (krb__get_srvtabname): Make retname be a static
+       array rather than a static pointer, to avoid callers' possible
+       retention of free()d pointers.  Yes, this may cause difficulty
+       with making this function thread-safe.
+
 2003-06-04  Tom Yu  <tlyu@mit.edu>
 
        * password_to_key.c (mit_passwd_to_key, afs_passwd_to_key): Delete
index 8d61f50565aaef7576489682d057d10b288b7ad0..dd5ed5c60d3cd272329e328334280979f5dbd573 100644 (file)
@@ -56,7 +56,7 @@ krb__get_srvtabname(default_srvtabname)
        const char* names[3];
        char **full_name = 0, **cpp;
        krb5_error_code retval;
-       static char *retname;
+       static char retname[MAXPATHLEN];
 
        if (!krb5__krb4_context)
                krb5_init_context(&krb5__krb4_context);
@@ -67,18 +67,16 @@ krb__get_srvtabname(default_srvtabname)
            retval = profile_get_values(krb5__krb4_context->profile, names, 
                                        &full_name);
            if (retval == 0 && full_name && full_name[0]) {
-               if (retname != NULL)
-                   free(retname);
-               retname = strdup(full_name[0]);
+               retname[0] = '\0';
+               strncat(retname, full_name[0], sizeof(retname));
                for (cpp = full_name; *cpp; cpp++) 
                    krb5_xfree(*cpp);
                krb5_xfree(full_name);
                return retname;
            }
        }
-       if (retname != NULL)
-           free(retname);
-       retname = strdup(default_srvtabname);
+       retname[0] = '\0';
+       strncat(retname, default_srvtabname, sizeof(retname));
        return retname;
 }