krb5 commit: Constify krb5_string_to_keysalts()'s string arg

Greg Hudson ghudson at MIT.EDU
Mon Jul 30 19:11:49 EDT 2012


https://github.com/krb5/krb5/commit/3576bd662be9b7cc2cca97065fe467e745542b69
commit 3576bd662be9b7cc2cca97065fe467e745542b69
Author: Nicolas Williams <nico at cryptonector.com>
Date:   Wed Jul 25 23:00:49 2012 -0500

    Constify krb5_string_to_keysalts()'s string arg

 src/include/adm_proto.h        |    6 +++---
 src/lib/kadm5/admin_internal.h |    2 +-
 src/lib/kadm5/srv/svr_policy.c |    2 +-
 src/lib/kadm5/str_conv.c       |   22 ++++++++++++----------
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/include/adm_proto.h b/src/include/adm_proto.h
index c6d1425..d79e362 100644
--- a/src/include/adm_proto.h
+++ b/src/include/adm_proto.h
@@ -100,7 +100,7 @@ krb5_error_code krb5_keysalt_iterate(krb5_key_salt_tuple *, krb5_int32,
                                                          krb5_pointer),
                                      krb5_pointer);
 
-krb5_error_code krb5_string_to_keysalts(char *, const char *, const char *,
-                                        krb5_boolean, krb5_key_salt_tuple **,
-                                        krb5_int32 *);
+krb5_error_code krb5_string_to_keysalts(const char *, const char *,
+                                        const char *, krb5_boolean,
+                                        krb5_key_salt_tuple **, krb5_int32 *);
 #endif  /* KRB5_ADM_PROTO_H__ */
diff --git a/src/lib/kadm5/admin_internal.h b/src/lib/kadm5/admin_internal.h
index 6d79243..ec604b2 100644
--- a/src/lib/kadm5/admin_internal.h
+++ b/src/lib/kadm5/admin_internal.h
@@ -70,7 +70,7 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle,
    maybe shouldn't be named krb5_*, but they are. */
 
 krb5_error_code
-krb5_string_to_keysalts(char *string, const char *tupleseps,
+krb5_string_to_keysalts(const char *string, const char *tupleseps,
                         const char *ksaltseps, krb5_boolean dups,
                         krb5_key_salt_tuple **ksaltp, krb5_int32 *nksaltp);
 
diff --git a/src/lib/kadm5/srv/svr_policy.c b/src/lib/kadm5/srv/svr_policy.c
index 3a8f82e..0d79f86 100644
--- a/src/lib/kadm5/srv/svr_policy.c
+++ b/src/lib/kadm5/srv/svr_policy.c
@@ -54,7 +54,7 @@ kadm5_create_policy(void *server_handle,
 
 /* Validate allowed_keysalts. */
 static kadm5_ret_t
-validate_allowed_keysalts(char *allowed_keysalts)
+validate_allowed_keysalts(const char *allowed_keysalts)
 {
     kadm5_ret_t ret;
     krb5_key_salt_tuple *ks_tuple = NULL;
diff --git a/src/lib/kadm5/str_conv.c b/src/lib/kadm5/str_conv.c
index 37a27dd..cdd2786 100644
--- a/src/lib/kadm5/str_conv.c
+++ b/src/lib/kadm5/str_conv.c
@@ -251,16 +251,12 @@ krb5_keysalt_is_present(ksaltlist, nksalts, enctype, salttype)
  *                                of key/salt tuples.
  */
 krb5_error_code
-krb5_string_to_keysalts(string, tupleseps, ksaltseps, dups, ksaltp, nksaltp)
-    char                *string;
-    const char          *tupleseps;
-    const char          *ksaltseps;
-    krb5_boolean        dups;
-    krb5_key_salt_tuple **ksaltp;
-    krb5_int32          *nksaltp;
+krb5_string_to_keysalts(const char *string, const char *tupleseps,
+                        const char *ksaltseps, krb5_boolean dups,
+                        krb5_key_salt_tuple **ksaltp, krb5_int32 *nksaltp)
 {
     krb5_error_code     kret;
-    char                *kp, *sp, *ep;
+    char                *dup_string, *kp, *sp, *ep;
     char                sepchar = 0, trailchar = 0;
     krb5_enctype        ktype;
     krb5_int32          stype;
@@ -271,7 +267,10 @@ krb5_string_to_keysalts(string, tupleseps, ksaltseps, dups, ksaltp, nksaltp)
     size_t              len;
 
     kret = 0;
-    kp = string;
+    dup_string = strdup(string);
+    if (dup_string == NULL)
+        return ENOMEM;
+    kp = dup_string;
     tseplist = (tupleseps) ? tupleseps : default_tupleseps;
     ksseplist = (ksaltseps) ? ksaltseps : default_ksaltseps;
     while (kp) {
@@ -346,8 +345,10 @@ krb5_string_to_keysalts(string, tupleseps, ksaltseps, dups, ksaltp, nksaltp)
                 break;
             }
         }
-        if (kret)
+        if (kret) {
+            free(dup_string);
             return kret;
+        }
         if (sp)
             sp[-1] = sepchar;
         if (ep)
@@ -369,6 +370,7 @@ krb5_string_to_keysalts(string, tupleseps, ksaltseps, dups, ksaltp, nksaltp)
             if (!*kp) kp = NULL;
         }
     } /* while kp */
+    free(dup_string);
     return(kret);
 }
 


More information about the cvs-krb5 mailing list