krb5 commit: Using k5-int.h data helpers for some functions

Greg Hudson ghudson at MIT.EDU
Fri Mar 29 11:41:35 EDT 2013


https://github.com/krb5/krb5/commit/61ab05d3b647971f2fc9481e7498176626a13707
commit 61ab05d3b647971f2fc9481e7498176626a13707
Author: Greg Hudson <ghudson at mit.edu>
Date:   Thu Mar 28 16:43:30 2013 -0400

    Using k5-int.h data helpers for some functions
    
    Use empty_data(), alloc_data(), and make_data() in some appropriate
    places.  This has the side effect of initializing the krb5_data magic
    field, which can placate debugging tools.

 src/lib/gssapi/krb5/k5sealv3.c |   17 +++++++----------
 src/lib/krb5/krb/pr_to_salt.c  |    9 +++------
 src/lib/krb5/os/read_msg.c     |    9 ++++-----
 3 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/src/lib/gssapi/krb5/k5sealv3.c b/src/lib/gssapi/krb5/k5sealv3.c
index c291e0f..e4c2c2f 100644
--- a/src/lib/gssapi/krb5/k5sealv3.c
+++ b/src/lib/gssapi/krb5/k5sealv3.c
@@ -126,10 +126,9 @@ gss_krb5int_make_seal_token_v3 (krb5_context context,
 #else
         ec = 0;
 #endif
-        plain.length = message->length + 16 + ec;
-        plain.data = malloc(message->length + 16 + ec);
-        if (plain.data == NULL)
-            return ENOMEM;
+        err = alloc_data(&plain, message->length + 16 + ec);
+        if (err)
+            return err;
 
         /* Get size of ciphertext.  */
         bufsize = 16 + krb5_encrypt_size (plain.length, key->keyblock.enctype);
@@ -190,10 +189,9 @@ gss_krb5int_make_seal_token_v3 (krb5_context context,
         tok_id = KG2_TOK_WRAP_MSG;
 
     wrap_with_checksum:
-        plain.length = message->length + 16;
-        plain.data = malloc(message->length + 16);
-        if (plain.data == NULL)
-            return ENOMEM;
+        err = alloc_data(&plain, message->length + 16);
+        if (err)
+            return err;
 
         err = krb5_c_checksum_length(context, cksumtype, &cksumsize);
         if (err)
@@ -442,8 +440,7 @@ gss_krb5int_unseal_token_v3(krb5_context *contextptr,
                Rotate the first two.  */
             store_16_be(0, ptr+4);
             store_16_be(0, ptr+6);
-            plain.length = bodysize-ec;
-            plain.data = (char *)ptr;
+            plain = make_data(ptr, bodysize - ec);
             if (!gss_krb5int_rotate_left(ptr, bodysize-ec, 16))
                 goto no_mem;
             sum.length = ec;
diff --git a/src/lib/krb5/krb/pr_to_salt.c b/src/lib/krb5/krb/pr_to_salt.c
index 416c1ef..53fc0ae 100644
--- a/src/lib/krb5/krb/pr_to_salt.c
+++ b/src/lib/krb5/krb/pr_to_salt.c
@@ -42,11 +42,9 @@ principal2salt_internal(krb5_context context,
     krb5_int32 nelem;
     register int i;
 
-    if (pr == 0) {
-        ret->length = 0;
-        ret->data = 0;
+    *ret = empty_data();
+    if (pr == NULL)
         return 0;
-    }
 
     nelem = krb5_princ_size(context, pr);
 
@@ -56,8 +54,7 @@ principal2salt_internal(krb5_context context,
     for (i = 0; i < (int) nelem; i++)
         size += krb5_princ_component(context, pr, i)->length;
 
-    ret->length = size;
-    if (!(ret->data = malloc (size)))
+    if (alloc_data(ret, size))
         return ENOMEM;
 
     if (use_realm) {
diff --git a/src/lib/krb5/os/read_msg.c b/src/lib/krb5/os/read_msg.c
index 2da310d..6c80d53 100644
--- a/src/lib/krb5/os/read_msg.c
+++ b/src/lib/krb5/os/read_msg.c
@@ -35,8 +35,7 @@ krb5_read_message(krb5_context context, krb5_pointer fdp, krb5_data *inbuf)
     char            *buf = NULL;
     int             fd = *( (int *) fdp);
 
-    inbuf->data = NULL;
-    inbuf->length = 0;
+    *inbuf = empty_data();
 
     if ((len2 = krb5_net_read(context, fd, (char *)&len, 4)) != 4)
         return((len2 < 0) ? errno : ECONNABORTED);
@@ -45,12 +44,12 @@ krb5_read_message(krb5_context context, krb5_pointer fdp, krb5_data *inbuf)
     if ((len & VALID_UINT_BITS) != (krb5_ui_4) len)  /* Overflow size_t??? */
         return ENOMEM;
 
-    inbuf->length = ilen = (int) len;
+    ilen = (int)len;
     if (ilen) {
         /*
          * We may want to include a sanity check here someday....
          */
-        if (!(buf = malloc(inbuf->length))) {
+        if (!(buf = malloc(ilen))) {
             return(ENOMEM);
         }
         if ((len2 = krb5_net_read(context, fd, buf, ilen)) != ilen) {
@@ -58,6 +57,6 @@ krb5_read_message(krb5_context context, krb5_pointer fdp, krb5_data *inbuf)
             return((len2 < 0) ? errno : ECONNABORTED);
         }
     }
-    inbuf->data = buf;
+    *inbuf = make_data(buf, ilen);
     return(0);
 }


More information about the cvs-krb5 mailing list