From: Tom Yu Date: Sat, 9 Jul 1994 02:29:00 +0000 (+0000) Subject: * asn1_decode_k.c: yet another instance of the SunOS realloc bug X-Git-Tag: krb5-1.0-beta4.2~150 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=219af439f0c3d45e920065f1a6094008266dcf4c;p=krb5.git * asn1_decode_k.c: yet another instance of the SunOS realloc bug * asn1buf.c: whee SunOS realloc of a NULL pointer returns NULL. sigh. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3961 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog index a8d2e3cac..fd722eb15 100644 --- a/src/lib/krb5/asn.1/ChangeLog +++ b/src/lib/krb5/asn.1/ChangeLog @@ -1,3 +1,10 @@ +Fri Jul 8 17:32:29 1994 Tom Yu (tlyu at dragons-lair) + + * asn1_decode_k.c: yet another instance of the SunOS realloc bug + + * asn1buf.c: whee SunOS realloc of a NULL pointer returns NULL. + sigh. + Wed Jul 6 13:21:35 1994 Mark Eichin (eichin@cygnus.com) * an1buf.c: Harry saves vs. Unix again. Making sure that anything diff --git a/src/lib/krb5/asn.1/asn1_decode_k.c b/src/lib/krb5/asn.1/asn1_decode_k.c index 734d7aa41..3d64d14f7 100644 --- a/src/lib/krb5/asn.1/asn1_decode_k.c +++ b/src/lib/krb5/asn.1/asn1_decode_k.c @@ -203,8 +203,11 @@ asn1_error_code asn1_decode_principal_name(DECLARG(asn1buf *, buf), { sequence_of(&subbuf); while(asn1buf_remains(&seqbuf)){ size++; - (*val)->data = (krb5_data*)realloc((*val)->data, - size*sizeof(krb5_data)); + if ((*val)->data == NULL) + (*val)->data = (krb5_data*)malloc(size*sizeof(krb5_data)); + else + (*val)->data = (krb5_data*)realloc((*val)->data, + size*sizeof(krb5_data)); if((*val)->data == NULL) return ENOMEM; retval = asn1_decode_generalstring(&seqbuf, &((*val)->data[size-1].length), @@ -490,8 +493,11 @@ if(retval) return retval #define array_append(array,size,element,type)\ size++;\ -*(array) = (type**)realloc(*(array),\ - (size+1)*sizeof(type*));\ +if (*(array) == NULL)\ + *(array) = (type**)malloc((size+1)*sizeof(type*));\ +else\ + *(array) = (type**)realloc(*(array),\ + (size+1)*sizeof(type*));\ if(*(array) == NULL) return ENOMEM;\ (*(array))[(size)-1] = elt diff --git a/src/lib/krb5/asn.1/asn1buf.c b/src/lib/krb5/asn.1/asn1buf.c index cc8cf7115..393014ddd 100644 --- a/src/lib/krb5/asn.1/asn1buf.c +++ b/src/lib/krb5/asn.1/asn1buf.c @@ -332,11 +332,15 @@ asn1_error_code asn1buf_expand(DECLARG(asn1buf *, buf), if(buf->base == NULL) bound_offset = -1; else bound_offset = buf->bound - buf->base; - - buf->base = realloc(buf->base, - (asn1buf_size(buf)+(inc>STANDARD_INCREMENT ? - inc : STANDARD_INCREMENT)) - * sizeof(asn1_octet)); + if (buf->base == NULL) + buf->base = malloc((asn1buf_size(buf)+(inc>STANDARD_INCREMENT ? + inc : STANDARD_INCREMENT)) + * sizeof(asn1_octet)); + else + buf->base = realloc(buf->base, + (asn1buf_size(buf)+(inc>STANDARD_INCREMENT ? + inc : STANDARD_INCREMENT)) + * sizeof(asn1_octet)); if(buf->base == NULL) return ENOMEM; buf->bound = (buf->base) + bound_offset + inc; buf->next = (buf->base) + next_offset;