aboutsummaryrefslogtreecommitdiff
path: root/src/lib/krb5/krb/copy_princ.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/krb5/krb/copy_princ.c')
-rw-r--r--src/lib/krb5/krb/copy_princ.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/lib/krb5/krb/copy_princ.c b/src/lib/krb5/krb/copy_princ.c
index 569e55b..f623236 100644
--- a/src/lib/krb5/krb/copy_princ.c
+++ b/src/lib/krb5/krb/copy_princ.c
@@ -60,32 +60,36 @@ krb5_copy_principal(krb5_context context, krb5_const_principal inprinc, krb5_pri
for (i = 0; i < nelems; i++) {
unsigned int len = krb5_princ_component(context, inprinc, i)->length;
krb5_princ_component(context, tempprinc, i)->length = len;
- if (((krb5_princ_component(context, tempprinc, i)->data =
- malloc(len)) == 0) && len) {
- while (--i >= 0)
- free(krb5_princ_component(context, tempprinc, i)->data);
- free (tempprinc->data);
- free (tempprinc);
- return ENOMEM;
- }
- if (len)
+ if (len) {
+ if (((krb5_princ_component(context, tempprinc, i)->data =
+ malloc(len)) == 0)) {
+ while (--i >= 0)
+ free(krb5_princ_component(context, tempprinc, i)->data);
+ free (tempprinc->data);
+ free (tempprinc);
+ return ENOMEM;
+ }
memcpy(krb5_princ_component(context, tempprinc, i)->data,
krb5_princ_component(context, inprinc, i)->data, len);
+ } else
+ krb5_princ_component(context, tempprinc, i)->data = 0;
}
- tempprinc->realm.data =
+ if (tempprinc->realm.length) {
+ tempprinc->realm.data =
malloc(tempprinc->realm.length = inprinc->realm.length);
- if (!tempprinc->realm.data && tempprinc->realm.length) {
+ if (!tempprinc->realm.data) {
for (i = 0; i < nelems; i++)
- free(krb5_princ_component(context, tempprinc, i)->data);
+ free(krb5_princ_component(context, tempprinc, i)->data);
free(tempprinc->data);
free(tempprinc);
return ENOMEM;
- }
- if (tempprinc->realm.length)
+ }
memcpy(tempprinc->realm.data, inprinc->realm.data,
inprinc->realm.length);
-
+ } else
+ tempprinc->realm.data = 0;
+
*outprinc = tempprinc;
return 0;
}