krb5 commit: Use gssalloc in more parts of GSSAPI

Greg Hudson ghudson at MIT.EDU
Sat Aug 11 00:30:29 EDT 2012


https://github.com/krb5/krb5/commit/b0edf38aafe3a365821cae4874e4608f95e28896
commit b0edf38aafe3a365821cae4874e4608f95e28896
Author: Greg Hudson <ghudson at mit.edu>
Date:   Sat Aug 11 00:13:05 2012 -0400

    Use gssalloc in more parts of GSSAPI
    
    Fix some GSSAPI buffer allocations which were missed in
    800358b1790ef82710af0b6021c6ff2dca2b0de7: gss_export_sec_context,
    gss_display_name, and IAKERB and SPNEGO token construction.
    
    ticket: 7233 (new)
    tags: pullup

 src/lib/gssapi/krb5/export_sec_context.c |    2 +-
 src/lib/gssapi/krb5/iakerb.c             |    6 ++++--
 src/lib/gssapi/mechglue/g_dsp_name.c     |    2 +-
 src/lib/gssapi/mechglue/g_glue.c         |    2 +-
 src/lib/gssapi/spnego/spnego_mech.c      |   12 ++++++------
 5 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/lib/gssapi/krb5/export_sec_context.c b/src/lib/gssapi/krb5/export_sec_context.c
index cdd20bd..18a3a34 100644
--- a/src/lib/gssapi/krb5/export_sec_context.c
+++ b/src/lib/gssapi/krb5/export_sec_context.c
@@ -57,7 +57,7 @@ krb5_gss_export_sec_context(minor_status, context_handle, interprocess_token)
         goto error_out;
 
     /* Allocate the buffer */
-    if ((obuffer = (krb5_octet *) xmalloc(bufsize)) == NULL) {
+    if ((obuffer = gssalloc_malloc(bufsize)) == NULL) {
         kret = ENOMEM;
         goto error_out;
     }
diff --git a/src/lib/gssapi/krb5/iakerb.c b/src/lib/gssapi/krb5/iakerb.c
index 2564276..8c6a082 100644
--- a/src/lib/gssapi/krb5/iakerb.c
+++ b/src/lib/gssapi/krb5/iakerb.c
@@ -286,9 +286,11 @@ iakerb_make_token(iakerb_ctx_id_t ctx,
     else
         tokenSize = 2 + data->length;
 
-    token->value = q = k5alloc(tokenSize, &code);
-    if (code != 0)
+    token->value = q = gssalloc_malloc(tokenSize);
+    if (q == NULL) {
+        code = ENOMEM;
         goto cleanup;
+    }
     token->length = tokenSize;
 
     if (initialContextToken) {
diff --git a/src/lib/gssapi/mechglue/g_dsp_name.c b/src/lib/gssapi/mechglue/g_dsp_name.c
index 2540f21..825bf4d 100644
--- a/src/lib/gssapi/mechglue/g_dsp_name.c
+++ b/src/lib/gssapi/mechglue/g_dsp_name.c
@@ -119,7 +119,7 @@ gss_OID *		output_name_type;
     }
 
     if ((output_name_buffer->value =
-	 malloc(union_name->external_name->length + 1)) == NULL) {
+	 gssalloc_malloc(union_name->external_name->length + 1)) == NULL) {
 	if (output_name_type && *output_name_type != GSS_C_NULL_OID) {
 	    (void) generic_gss_release_oid(minor_status,
 					   output_name_type);
diff --git a/src/lib/gssapi/mechglue/g_glue.c b/src/lib/gssapi/mechglue/g_glue.c
index a9b6f35..e9ff4c8 100644
--- a/src/lib/gssapi/mechglue/g_glue.c
+++ b/src/lib/gssapi/mechglue/g_glue.c
@@ -472,7 +472,7 @@ OM_uint32 gssint_export_internal_name(minor_status, mech_type,
 	mechOidTagLen + mechOidDERLen +
 	mech_type->length +
 	nameLenLen + dispName.length;
-    if ((name_buf->value = (void*)malloc(name_buf->length)) ==
+    if ((name_buf->value = (void*)gssalloc_malloc(name_buf->length)) ==
 	(void*)NULL) {
 	name_buf->length = 0;
 	(void) gss_release_buffer(&status, &dispName);
diff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c
index c5c995b..e207d27 100644
--- a/src/lib/gssapi/spnego/spnego_mech.c
+++ b/src/lib/gssapi/spnego/spnego_mech.c
@@ -1207,7 +1207,7 @@ make_NegHints(OM_uint32 *minor_status,
 	tlen += 1 + gssint_der_length_size(hintNameSize);
 	negHintsSize = tlen;
 
-	t = (unsigned char *)malloc(tlen);
+	t = gssalloc_malloc(tlen);
 	if (t == NULL) {
 		*minor_status = ENOMEM;
 		goto errout;
@@ -3076,7 +3076,7 @@ get_input_token(unsigned char **buff_in, unsigned int buff_length)
 		return (NULL);
 
 	input_token->length = len;
-	input_token->value = malloc(input_token->length);
+	input_token->value = gssalloc_malloc(input_token->length);
 
 	if (input_token->value == NULL) {
 		free(input_token);
@@ -3189,7 +3189,7 @@ put_mech_set(gss_OID_set mechSet, gss_buffer_t buf)
 	 * 0x30 [DER LEN]
 	 */
 	tlen = 1 + gssint_der_length_size(ilen) + ilen;
-	ptr = malloc(tlen);
+	ptr = gssalloc_malloc(tlen);
 	if (ptr == NULL)
 		return -1;
 
@@ -3287,7 +3287,7 @@ get_negTokenInit(OM_uint32 *minor_status,
 		return GSS_S_FAILURE;
 
 	tmpbuf.length = ptr - (unsigned char *)tmpbuf.value;
-	der_mechSet->value = malloc(tmpbuf.length);
+	der_mechSet->value = gssalloc_malloc(tmpbuf.length);
 	if (der_mechSet->value == NULL)
 		return GSS_S_FAILURE;
 	memcpy(der_mechSet->value, tmpbuf.value, tmpbuf.length);
@@ -3598,7 +3598,7 @@ make_spnego_tokenInit_msg(spnego_gss_ctx_id_t spnego_ctx,
 
 	tlen = g_token_size(gss_mech_spnego, negTokenInitSize);
 
-	t = (unsigned char *) malloc(tlen);
+	t = (unsigned char *) gssalloc_malloc(tlen);
 
 	if (t == NULL) {
 		return (-1);
@@ -3774,7 +3774,7 @@ make_spnego_tokenTarg_msg(OM_uint32 status, gss_OID mech_wanted,
 	dataLen += 1 + gssint_der_length_size(NegTokenSize);
 
 	tlen = dataLen;
-	t = (unsigned char *) malloc(tlen);
+	t = (unsigned char *) gssalloc_malloc(tlen);
 
 	if (t == NULL) {
 		ret = GSS_S_DEFECTIVE_TOKEN;


More information about the cvs-krb5 mailing list