From dc05c6ceaa143415b8605f8a2b6f8579687059ed Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Tue, 23 Feb 1993 14:19:33 +0000 Subject: [PATCH] Added fix to avoid the malloc(0) problem git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2500 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/asn.1/kdcr2kkdcr.c | 23 +++++++++++++---------- src/lib/krb5/asn.1/tgrq2ktgrq.c | 22 ++++++++++++---------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/lib/krb5/asn.1/kdcr2kkdcr.c b/src/lib/krb5/asn.1/kdcr2kkdcr.c index 0e3cf5f4d..412e5a69d 100644 --- a/src/lib/krb5/asn.1/kdcr2kkdcr.c +++ b/src/lib/krb5/asn.1/kdcr2kkdcr.c @@ -72,18 +72,21 @@ element_KRB5_112krb5_pa_data(val, error) *error = ENOMEM; return(0); } - retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len); - if (!retval[i]->contents) { - xfree(retval[i]); - retval[i] = 0; - krb5_free_pa_data(retval); - *error = ENOMEM; - return(0); - } retval[i]->pa_type = rv->PA__DATA->padata__type; retval[i]->length = rv->PA__DATA->pa__data->qb_forw->qb_len; - xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data, - retval[i]->contents, retval[i]->length); + if (retval[i]->length) { + retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len); + if (!retval[i]->contents) { + xfree(retval[i]); + retval[i] = 0; + krb5_free_pa_data(retval); + *error = ENOMEM; + return(0); + } + xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data, + retval[i]->contents, retval[i]->length); + } else + retval[i]->contents = 0; } retval[i] = 0; return(retval); diff --git a/src/lib/krb5/asn.1/tgrq2ktgrq.c b/src/lib/krb5/asn.1/tgrq2ktgrq.c index 8a08d880c..ea14beeb9 100644 --- a/src/lib/krb5/asn.1/tgrq2ktgrq.c +++ b/src/lib/krb5/asn.1/tgrq2ktgrq.c @@ -232,18 +232,20 @@ element_KRB5_72krb5_pa_data(val, error) *error = ENOMEM; return(0); } - retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len); - if (!retval[i]->contents) { - xfree(retval[i]); - retval[i] = 0; - krb5_free_pa_data(retval); - *error = ENOMEM; - return(0); - } retval[i]->pa_type = rv->PA__DATA->padata__type; retval[i]->length = rv->PA__DATA->pa__data->qb_forw->qb_len; - xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data, - retval[i]->contents, retval[i]->length); + if (retval[i]->length) { + retval[i]->contents = (unsigned char *)xmalloc(rv->PA__DATA->pa__data->qb_forw->qb_len); + if (!retval[i]->contents) { + xfree(retval[i]); + retval[i] = 0; + krb5_free_pa_data(retval); + *error = ENOMEM; + return(0); + } + xbcopy(rv->PA__DATA->pa__data->qb_forw->qb_data, + retval[i]->contents, retval[i]->length); + } } retval[i] = 0; return(retval); -- 2.26.2