From: Theodore Tso Date: Tue, 23 Feb 1993 00:54:21 +0000 (+0000) Subject: Added include for errno.h; check for length = 0 before allocating: for X-Git-Tag: krb5-1.0-beta3~332 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=790da6d9f0434b4fe967de7eb673a6762335bba7;p=krb5.git Added include for errno.h; check for length = 0 before allocating: for malloc()'s where malloc(0) can return 0. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2497 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/ccache/file/fcc_read.c b/src/lib/krb5/ccache/file/fcc_read.c index 660e41c69..ac5a3eba0 100644 --- a/src/lib/krb5/ccache/file/fcc_read.c +++ b/src/lib/krb5/ccache/file/fcc_read.c @@ -31,6 +31,7 @@ static char rcsid_fcc_read_c[] = "$Id$"; #endif /* !lint && !SABER */ +#include #include "fcc.h" #define CHECK(ret) if (ret != KRB5_OK) goto errout; @@ -105,11 +106,14 @@ krb5_fcc_read_principal(id, princ) tmpprinc = (krb5_principal) malloc(sizeof(krb5_principal_data)); if (tmpprinc == NULL) return KRB5_CC_NOMEM; - tmpprinc->data = (krb5_data *) malloc(length * sizeof(krb5_data)); - if (tmpprinc->data == 0) { - free((char *)tmpprinc); - return KRB5_CC_NOMEM; - } + if (length) { + tmpprinc->data = (krb5_data *) malloc(length * sizeof(krb5_data)); + if (tmpprinc->data == 0) { + free((char *)tmpprinc); + return KRB5_CC_NOMEM; + } + } else + tmpprinc->data = 0; tmpprinc->length = length; tmpprinc->type = type; @@ -186,6 +190,8 @@ krb5_fcc_read_keyblock(id, keyblock) CHECK(kret); kret = krb5_fcc_read_int(id, &keyblock->length); CHECK(kret); + if ( keyblock->length == 0 ) + return KRB5_OK; keyblock->contents = (unsigned char *) malloc(keyblock->length* sizeof(krb5_octet)); if (keyblock->contents == NULL) @@ -266,6 +272,9 @@ krb5_fcc_read_addr(id, addr) kret = krb5_fcc_read_int(id, &addr->length); CHECK(kret); + if (addr->length == 0) + return KRB5_OK; + addr->contents = (krb5_octet *) malloc(addr->length); if (addr->contents == NULL) return KRB5_CC_NOMEM; @@ -400,6 +409,9 @@ krb5_fcc_read_authdatum(id, a) kret = krb5_fcc_read_int(id, &a->length); CHECK(kret); + if (a->length == 0 ) + return KRB5_OK; + a->contents = (krb5_octet *) malloc(a->length); if (a->contents == NULL) return KRB5_CC_NOMEM;