From 6b5da137191fb8fb47d970db2e887fed7040771f Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Wed, 10 Jun 1992 20:49:25 +0000 Subject: [PATCH] Checked in jfc's changes to krb5_copy_principal git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2292 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/krb/copy_princ.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/lib/krb5/krb/copy_princ.c b/src/lib/krb5/krb/copy_princ.c index 6b80ec242..bff89b47e 100644 --- a/src/lib/krb5/krb/copy_princ.c +++ b/src/lib/krb5/krb/copy_princ.c @@ -42,22 +42,33 @@ krb5_copy_principal(inprinc, outprinc) krb5_const_principal inprinc; krb5_principal *outprinc; { - krb5_error_code retval; - krb5_principal tempprinc; - register int nelems; + register krb5_principal tempprinc; + register int i, nelems; - for (nelems = 0; inprinc[nelems]; nelems++); + tempprinc = (krb5_principal)malloc(sizeof(krb5_principal_data)); - /* one more for a null terminated list */ - if (!(tempprinc = (krb5_principal) calloc(nelems+1, sizeof(krb5_data *)))) + if (tempprinc == 0) return ENOMEM; - for (nelems = 0; inprinc[nelems]; nelems++) - if (retval = krb5_copy_data(inprinc[nelems], &tempprinc[nelems])) { - krb5_free_principal(tempprinc); - return retval; - } + nelems = krb5_princ_size(inprinc); + tempprinc->data = malloc(nelems * sizeof(krb5_data)); + + if (tempprinc->data == 0) { + free((char *)tempprinc); + return ENOMEM; + } + for (i = 0; i < nelems; i++) { + int len = krb5_princ_component(inprinc, i)->length; + krb5_princ_component(tempprinc, i)->length = len; + if ((krb5_princ_component(tempprinc, i)->data = malloc(len)) == 0) { + while (--i >= 0) + free(krb5_princ_component(tempprinc, i)->data); + free (tempprinc->data); + free (tempprinc); + return ENOMEM; + } + } *outprinc = tempprinc; return 0; } -- 2.26.2