From 26415263231eaafd37f5c361a63e5ab75feb8703 Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Sat, 27 Jul 1996 02:23:23 +0000 Subject: [PATCH] It's not an out-of-space error if malloc(0) returns 0. So, when copying key_data, only call malloc if the length is non-zero. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@8850 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kadm5/srv/ChangeLog | 6 ++++++ src/lib/kadm5/srv/svr_principal.c | 28 +++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/lib/kadm5/srv/ChangeLog b/src/lib/kadm5/srv/ChangeLog index 0011ab863..d771d96a6 100644 --- a/src/lib/kadm5/srv/ChangeLog +++ b/src/lib/kadm5/srv/ChangeLog @@ -1,3 +1,9 @@ +Fri Jul 26 17:48:14 1996 Sam Hartman + + * svr_principal.c (krb5_copy_key_data_contents): If + key_data_length[i] == 0, don't complain if malloc(0) returns 0; + this is allowed by ANSI. + Thu Jul 25 18:42:47 1996 Sam Hartman * configure.in (LIBS): Link against -ldb under AIX for shared diff --git a/src/lib/kadm5/srv/svr_principal.c b/src/lib/kadm5/srv/svr_principal.c index 6f9671fcf..c8dcdd66d 100644 --- a/src/lib/kadm5/srv/svr_principal.c +++ b/src/lib/kadm5/srv/svr_principal.c @@ -57,19 +57,21 @@ kadm5_ret_t krb5_copy_key_data_contents(context, from, to) idx = (from->key_data_ver == 1 ? 1 : 2); for (i = 0; i < idx; i++) { - to->key_data_contents[i] = malloc(from->key_data_length[i]); - if (to->key_data_contents[i] == NULL) { - for (i = 0; i < idx; i++) { - if (to->key_data_contents[i]) { - memset(to->key_data_contents[i], 0, - to->key_data_length[i]); - free(to->key_data_contents[i]); - } - } - return ENOMEM; - } - memcpy(to->key_data_contents[i], from->key_data_contents[i], - from->key_data_length[i]); + if ( from->key_data_length[i] ) { + to->key_data_contents[i] = malloc(from->key_data_length[i]); + if (to->key_data_contents[i] == NULL) { + for (i = 0; i < idx; i++) { + if (to->key_data_contents[i]) { + memset(to->key_data_contents[i], 0, + to->key_data_length[i]); + free(to->key_data_contents[i]); + } + } + return ENOMEM; + } + memcpy(to->key_data_contents[i], from->key_data_contents[i], + from->key_data_length[i]); + } } return 0; } -- 2.26.2