From 4a9370290f91b2a210dd4967039373663a4ea855 Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Fri, 4 Oct 1996 12:39:36 +0000 Subject: [PATCH] * client_principal.c (kadm5_randkey_principal): Do not assume that malloc(0) returns non-NULL. [krb5-admin/46] git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9142 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kadm5/clnt/ChangeLog | 5 +++++ src/lib/kadm5/clnt/client_principal.c | 31 +++++++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/lib/kadm5/clnt/ChangeLog b/src/lib/kadm5/clnt/ChangeLog index 422c5220e..42b505efa 100644 --- a/src/lib/kadm5/clnt/ChangeLog +++ b/src/lib/kadm5/clnt/ChangeLog @@ -1,3 +1,8 @@ +Fri Oct 4 08:38:16 1996 Ezra Peisach + + * client_principal.c (kadm5_randkey_principal): Do not assume that + malloc(0) returns non-NULL. [krb5-admin/46] + Mon Aug 26 16:33:31 1996 Barry Jaspan * client_init.c (_kadm5_init_any): use DEFAULT_PROFILE_PATH diff --git a/src/lib/kadm5/clnt/client_principal.c b/src/lib/kadm5/clnt/client_principal.c index c41922722..54ce1f30b 100644 --- a/src/lib/kadm5/clnt/client_principal.c +++ b/src/lib/kadm5/clnt/client_principal.c @@ -278,21 +278,24 @@ kadm5_randkey_principal(void *server_handle, if (n_keys) *n_keys = r->n_keys; if (key) { - *key = (krb5_keyblock *) malloc(r->n_keys*sizeof(krb5_keyblock)); - if (*key == NULL) - return ENOMEM; - for (i = 0; i < r->n_keys; i++) { - ret = krb5_copy_keyblock_contents(handle->context, - &r->keys[i], - &(*key)[i]); - if (ret) { - free(*key); - return ENOMEM; - } - } - } + if(r->n_keys) { + *key = (krb5_keyblock *) + malloc(r->n_keys*sizeof(krb5_keyblock)); + if (*key == NULL) + return ENOMEM; + for (i = 0; i < r->n_keys; i++) { + ret = krb5_copy_keyblock_contents(handle->context, + &r->keys[i], + &(*key)[i]); + if (ret) { + free(*key); + return ENOMEM; + } + } + } else *key = NULL; + } } - + return r->code; } -- 2.26.2