From 7530c993aea46757bce8ed34a4952198082504e7 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Tue, 18 Apr 1995 21:48:47 +0000 Subject: [PATCH] * sendauth.c (krb5_sendauth): initialize error return parameter * copy_princ.c (krb5_copy_principal): Fix bug where krb5_copy_principal can fail if it is asked to copy a principal with a zero-length component on a system where malloc(0) returns null. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5366 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/krb/ChangeLog | 9 +++++++++ src/lib/krb5/krb/copy_princ.c | 14 +++++++++----- src/lib/krb5/krb/sendauth.c | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/lib/krb5/krb/ChangeLog b/src/lib/krb5/krb/ChangeLog index 7dd6e6a5a..49925830d 100644 --- a/src/lib/krb5/krb/ChangeLog +++ b/src/lib/krb5/krb/ChangeLog @@ -1,3 +1,12 @@ +Fri Apr 14 15:05:51 1995 + + * sendauth.c (krb5_sendauth): initialize error return parameter + + * copy_princ.c (krb5_copy_principal): Fix bug where + krb5_copy_principal can fail if it is asked to copy a + principal with a zero-length component on a system where + malloc(0) returns null. + Thu Apr 13 15:49:16 1995 Keith Vetter (keithv@fusion.com) * *.[ch]: removed unneeded INTERFACE from non-api functions. diff --git a/src/lib/krb5/krb/copy_princ.c b/src/lib/krb5/krb/copy_princ.c index d8e47de2f..43836eb06 100644 --- a/src/lib/krb5/krb/copy_princ.c +++ b/src/lib/krb5/krb/copy_princ.c @@ -56,27 +56,31 @@ krb5_copy_principal(context, inprinc, outprinc) for (i = 0; i < nelems; i++) { 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) { + 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; } - memcpy(krb5_princ_component(context, tempprinc, i)->data, - krb5_princ_component(context, inprinc, i)->data, len); + if (len) + memcpy(krb5_princ_component(context, tempprinc, i)->data, + krb5_princ_component(context, inprinc, i)->data, len); } tempprinc->realm.data = malloc(tempprinc->realm.length = inprinc->realm.length); - if (!tempprinc->realm.data) { + if (!tempprinc->realm.data && tempprinc->realm.length) { for (i = 0; i < nelems; i++) free(krb5_princ_component(context, tempprinc, i)->data); free(tempprinc->data); free(tempprinc); return ENOMEM; } - memcpy(tempprinc->realm.data, inprinc->realm.data, inprinc->realm.length); + if (tempprinc->realm.length) + memcpy(tempprinc->realm.data, inprinc->realm.data, + inprinc->realm.length); *outprinc = tempprinc; return 0; diff --git a/src/lib/krb5/krb/sendauth.c b/src/lib/krb5/krb/sendauth.c index 1e890e8d6..dca998c6a 100644 --- a/src/lib/krb5/krb/sendauth.c +++ b/src/lib/krb5/krb/sendauth.c @@ -72,6 +72,9 @@ krb5_sendauth(context, auth_context, int len; krb5_ccache use_ccache = 0; + if (error) + *error = 0; + /* * First, send over the length of the sendauth version string; * then, we send over the sendauth version. Next, we send -- 2.26.2