From d9457b501cbab535e5968dbdf195ca334b9fa555 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 15 Jul 2013 12:20:26 -0400 Subject: Avoid allocating zero key_data structures When we allocate space for an array of key_data structures, make sure we allocate at least one, so we don't spuriously fail on platforms where malloc(0) returns NULL. Where we use malloc, use k5calloc instead. Where we use krb5_db_alloc or realloc, just allocate an extra entry. --- src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c index bcdc1dc47..c30599e72 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal2.c @@ -1380,7 +1380,8 @@ krb5_decode_krbsecretkey(krb5_context context, krb5_db_entry *entries, } noofkeys += n_kd; tmp = key_data; - key_data = realloc (key_data, noofkeys * sizeof (krb5_key_data)); + /* Allocate an extra key data to avoid allocating zero bytes. */ + key_data = realloc(key_data, (noofkeys + 1) * sizeof (krb5_key_data)); if (key_data == NULL) { key_data = tmp; st = ENOMEM; -- cgit