krb5 commit: Cast away constness when assigning to krb5_data

Tom Yu tlyu at mit.edu
Fri Dec 11 18:03:00 EST 2015


https://github.com/krb5/krb5/commit/e534f688db29945e4efde425f62ce7dae4608f6f
commit e534f688db29945e4efde425f62ce7dae4608f6f
Author: Tom Yu <tlyu at mit.edu>
Date:   Fri Dec 11 16:01:08 2015 -0500

    Cast away constness when assigning to krb5_data
    
    Some password-changing library functions take a const char * parameter
    but try to assign it to krb5_data.data, which isn't const.  PR #364
    causes some compilers to produce errors in such situations, so cast
    away the constness.  This is almost certainly safe because of the
    nature of the code that consumes these krb5_data values.

 src/lib/kdb/kdb_cpw.c   |    5 ++---
 src/lib/krb5/krb/chpw.c |    6 ++----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/lib/kdb/kdb_cpw.c b/src/lib/kdb/kdb_cpw.c
index 33017ec..8124078 100644
--- a/src/lib/kdb/kdb_cpw.c
+++ b/src/lib/kdb/kdb_cpw.c
@@ -299,7 +299,7 @@ add_key_pwd(context, master_key, ks_tuple, ks_tuple_count, passwd,
     krb5_keyblock       * master_key;
     krb5_key_salt_tuple * ks_tuple;
     int                   ks_tuple_count;
-    char                * passwd;
+    const char          * passwd;
     krb5_db_entry       * db_entry;
     int                   kvno;
 {
@@ -383,8 +383,7 @@ add_key_pwd(context, master_key, ks_tuple, ks_tuple_count, passwd,
             return(KRB5_KDB_BAD_SALTTYPE);
         }
 
-        pwd.data = passwd;
-        pwd.length = strlen(passwd);
+        pwd = string2data((char *)passwd);
 
         retval = krb5_c_string_to_key_with_params(context,
                                                   ks_tuple[i].ks_enctype,
diff --git a/src/lib/krb5/krb/chpw.c b/src/lib/krb5/krb/chpw.c
index 41a3cdd..cdec595 100644
--- a/src/lib/krb5/krb/chpw.c
+++ b/src/lib/krb5/krb/chpw.c
@@ -28,8 +28,7 @@ krb5int_mk_chpw_req(krb5_context context,
                                       KRB5_AUTH_CONTEXT_DO_SEQUENCE)))
         goto cleanup;
 
-    clearpw.length = strlen(passwd);
-    clearpw.data = passwd;
+    clearpw = string2data((char *)passwd);
 
     if ((ret = krb5_mk_priv(context, auth_context,
                             &clearpw, &cipherpw, &replay)))
@@ -302,8 +301,7 @@ krb5int_mk_setpw_req(krb5_context context,
         return(ret);
 
     req.target = targprinc;
-    req.password.data = passwd;
-    req.password.length = strlen(passwd);
+    req.password = string2data((char *)passwd);
     ret = encode_krb5_setpw_req(&req, &encoded_setpw);
     if (ret) {
         return ret;


More information about the cvs-krb5 mailing list