krb5 commit: Use k5calloc instead of k5alloc where appropriate
Greg Hudson
ghudson at MIT.EDU
Mon Jul 15 00:43:07 EDT 2013
https://github.com/krb5/krb5/commit/443ce5fef316e3dc324fe84557a06b069dbe33f9
commit 443ce5fef316e3dc324fe84557a06b069dbe33f9
Author: Greg Hudson <ghudson at mit.edu>
Date: Thu Jul 11 20:39:51 2013 -0400
Use k5calloc instead of k5alloc where appropriate
Wherever we use k5alloc with a multiplication in the size parameter,,
use the new k5calloc helper function instead.
src/kdc/kdc_authdata.c | 6 +++---
src/kdc/kdc_preauth.c | 2 +-
src/lib/crypto/builtin/hmac.c | 2 +-
src/lib/crypto/krb/cf2.c | 2 +-
src/lib/crypto/krb/checksum_confounder.c | 4 ++--
src/lib/crypto/krb/checksum_hmac_md5.c | 2 +-
src/lib/crypto/krb/combine_keys.c | 2 +-
src/lib/kadm5/srv/kadm5_hook.c | 2 +-
src/lib/kadm5/srv/pwqual.c | 2 +-
src/lib/kadm5/srv/server_kdb.c | 2 +-
src/lib/krb5/ccache/ccselect.c | 2 +-
src/lib/krb5/krb/preauth_encts.c | 2 +-
src/lib/krb5/krb/s4u_authdata.c | 8 ++++----
src/lib/krb5/krb/send_tgs.c | 2 +-
src/lib/krb5/os/expand_path.c | 2 +-
src/lib/krb5/os/localauth.c | 2 +-
src/plugins/kdb/hdb/kdb_marshal.c | 18 ++++++++++--------
src/plugins/kdb/hdb/kdb_windc.c | 4 ++--
src/plugins/preauth/otp/otp_state.c | 4 ++--
19 files changed, 36 insertions(+), 34 deletions(-)
diff --git a/src/kdc/kdc_authdata.c b/src/kdc/kdc_authdata.c
index 5a50a47..c029892 100644
--- a/src/kdc/kdc_authdata.c
+++ b/src/kdc/kdc_authdata.c
@@ -811,7 +811,7 @@ make_ad_signedpath_data(krb5_context context,
i = 0;
if (i != 0) {
- sign_authdata = k5alloc((i + 1) * sizeof(krb5_authdata *), &code);
+ sign_authdata = k5calloc(i + 1, sizeof(krb5_authdata *), &code);
if (sign_authdata == NULL)
return code;
@@ -1018,8 +1018,8 @@ make_ad_signedpath(krb5_context context,
} else
i = 0;
- sp.delegated = k5alloc((i + (server ? 1 : 0) + 1) *
- sizeof(krb5_principal), &code);
+ sp.delegated = k5calloc(i + (server ? 1 : 0) + 1, sizeof(krb5_principal),
+ &code);
if (code != 0)
goto cleanup;
diff --git a/src/kdc/kdc_preauth.c b/src/kdc/kdc_preauth.c
index 07b180f..50cc252 100644
--- a/src/kdc/kdc_preauth.c
+++ b/src/kdc/kdc_preauth.c
@@ -1367,7 +1367,7 @@ etype_info_helper(krb5_context context, krb5_kdc_req *request,
int i = 0, start = 0, seen_des = 0;
int etype_info2 = (pa_type == KRB5_PADATA_ETYPE_INFO2);
- entry = k5alloc((client->n_key_data * 2 + 1) * sizeof(*entry), &retval);
+ entry = k5calloc(client->n_key_data * 2 + 1, sizeof(*entry), &retval);
if (entry == NULL)
goto cleanup;
entry[0] = NULL;
diff --git a/src/lib/crypto/builtin/hmac.c b/src/lib/crypto/builtin/hmac.c
index c697a76..95c8f5f 100644
--- a/src/lib/crypto/builtin/hmac.c
+++ b/src/lib/crypto/builtin/hmac.c
@@ -71,7 +71,7 @@ krb5int_hmac_keyblock(const struct krb5_hash_provider *hash,
ihash = k5alloc(hash->hashsize, &ret);
if (ihash == NULL)
goto cleanup;
- ihash_iov = k5alloc((num_data + 1) * sizeof(krb5_crypto_iov), &ret);
+ ihash_iov = k5calloc(num_data + 1, sizeof(krb5_crypto_iov), &ret);
if (ihash_iov == NULL)
goto cleanup;
diff --git a/src/lib/crypto/krb/cf2.c b/src/lib/crypto/krb/cf2.c
index e6d990c..5eec154 100644
--- a/src/lib/crypto/krb/cf2.c
+++ b/src/lib/crypto/krb/cf2.c
@@ -56,7 +56,7 @@ prf_plus(krb5_context context, krb5_keyblock *k, const char *pepper,
if (keybytes % prflen != 0)
iterations++;
assert(iterations <= 254);
- buffer = k5alloc(iterations * prflen, &retval);
+ buffer = k5calloc(iterations, prflen, &retval);
if (retval)
goto cleanup;
if (k5_buf_len(&prf_inbuf) == -1) {
diff --git a/src/lib/crypto/krb/checksum_confounder.c b/src/lib/crypto/krb/checksum_confounder.c
index 0e54953..31c7cd3 100644
--- a/src/lib/crypto/krb/checksum_confounder.c
+++ b/src/lib/crypto/krb/checksum_confounder.c
@@ -83,7 +83,7 @@ krb5int_confounder_checksum(const struct krb5_cksumtypes *ctp,
return ret;
/* Hash the confounder, then the input data. */
- hash_iov = k5alloc((num_data + 1) * sizeof(krb5_crypto_iov), &ret);
+ hash_iov = k5calloc(num_data + 1, sizeof(krb5_crypto_iov), &ret);
if (hash_iov == NULL)
goto cleanup;
hash_iov[0].flags = KRB5_CRYPTO_TYPE_DATA;
@@ -134,7 +134,7 @@ krb5_error_code krb5int_confounder_verify(const struct krb5_cksumtypes *ctp,
goto cleanup;
/* Hash the confounder, then the input data. */
- hash_iov = k5alloc((num_data + 1) * sizeof(krb5_crypto_iov), &ret);
+ hash_iov = k5calloc(num_data + 1, sizeof(krb5_crypto_iov), &ret);
if (hash_iov == NULL)
goto cleanup;
hash_iov[0].flags = KRB5_CRYPTO_TYPE_DATA;
diff --git a/src/lib/crypto/krb/checksum_hmac_md5.c b/src/lib/crypto/krb/checksum_hmac_md5.c
index 8145875..ec024f3 100644
--- a/src/lib/crypto/krb/checksum_hmac_md5.c
+++ b/src/lib/crypto/krb/checksum_hmac_md5.c
@@ -68,7 +68,7 @@ krb5_error_code krb5int_hmacmd5_checksum(const struct krb5_cksumtypes *ctp,
/* Compute the MD5 value of the input. */
ms_usage = krb5int_arcfour_translate_usage(usage);
store_32_le(ms_usage, t);
- hash_iov = k5alloc((num_data + 1) * sizeof(krb5_crypto_iov), &ret);
+ hash_iov = k5calloc(num_data + 1, sizeof(krb5_crypto_iov), &ret);
if (hash_iov == NULL)
goto cleanup;
hash_iov[0].flags = KRB5_CRYPTO_TYPE_DATA;
diff --git a/src/lib/crypto/krb/combine_keys.c b/src/lib/crypto/krb/combine_keys.c
index d9235dd..0c44e8b 100644
--- a/src/lib/crypto/krb/combine_keys.c
+++ b/src/lib/crypto/krb/combine_keys.c
@@ -110,7 +110,7 @@ krb5int_c_combine_keys(krb5_context context, krb5_keyblock *key1,
rnd = k5alloc(keybytes, &ret);
if (ret)
goto cleanup;
- combined = k5alloc(keybytes * 2, &ret);
+ combined = k5calloc(2, keybytes, &ret);
if (ret)
goto cleanup;
output = k5alloc(keylength, &ret);
diff --git a/src/lib/kadm5/srv/kadm5_hook.c b/src/lib/kadm5/srv/kadm5_hook.c
index 68a6b5e..62f3bff 100644
--- a/src/lib/kadm5/srv/kadm5_hook.c
+++ b/src/lib/kadm5/srv/kadm5_hook.c
@@ -53,7 +53,7 @@ k5_kadm5_hook_load(krb5_context context,
/* Allocate a large enough list of handles. */
for (count = 0; modules[count] != NULL; count++);
- list = k5alloc((count + 1) * sizeof(*list), &ret);
+ list = k5calloc(count + 1, sizeof(*list), &ret);
if (list == NULL)
goto cleanup;
diff --git a/src/lib/kadm5/srv/pwqual.c b/src/lib/kadm5/srv/pwqual.c
index 8c53391..666852f 100644
--- a/src/lib/kadm5/srv/pwqual.c
+++ b/src/lib/kadm5/srv/pwqual.c
@@ -55,7 +55,7 @@ k5_pwqual_load(krb5_context context, const char *dict_file,
/* Allocate a large enough list of handles. */
for (count = 0; modules[count] != NULL; count++);
- list = k5alloc((count + 1) * sizeof(*list), &ret);
+ list = k5calloc(count + 1, sizeof(*list), &ret);
if (list == NULL)
goto cleanup;
diff --git a/src/lib/kadm5/srv/server_kdb.c b/src/lib/kadm5/srv/server_kdb.c
index 2366144..8a82237 100644
--- a/src/lib/kadm5/srv/server_kdb.c
+++ b/src/lib/kadm5/srv/server_kdb.c
@@ -188,7 +188,7 @@ kdb_get_hist_key(kadm5_server_handle_t handle, krb5_keyblock **keyblocks_out,
if (ret)
goto done;
- kblist = k5alloc((kdb->n_key_data + 1) * sizeof(*kblist), &ret);
+ kblist = k5calloc(kdb->n_key_data + 1, sizeof(*kblist), &ret);
if (kblist == NULL)
goto done;
for (i = 0; i < kdb->n_key_data; i++) {
diff --git a/src/lib/krb5/ccache/ccselect.c b/src/lib/krb5/ccache/ccselect.c
index 235c0c6..2f3071a 100644
--- a/src/lib/krb5/ccache/ccselect.c
+++ b/src/lib/krb5/ccache/ccselect.c
@@ -77,7 +77,7 @@ load_modules(krb5_context context)
/* Allocate a large enough list of handles. */
for (count = 0; modules[count] != NULL; count++);
- list = k5alloc((count + 1) * sizeof(*list), &ret);
+ list = k5calloc(count + 1, sizeof(*list), &ret);
if (list == NULL)
goto cleanup;
diff --git a/src/lib/krb5/krb/preauth_encts.c b/src/lib/krb5/krb/preauth_encts.c
index b8295aa..cec3842 100644
--- a/src/lib/krb5/krb/preauth_encts.c
+++ b/src/lib/krb5/krb/preauth_encts.c
@@ -92,7 +92,7 @@ encts_process(krb5_context context, krb5_clpreauth_moddata moddata,
if (ret)
goto cleanup;
- pa = k5alloc(2 * sizeof(krb5_pa_data *), &ret);
+ pa = k5calloc(2, sizeof(krb5_pa_data *), &ret);
if (pa == NULL)
goto cleanup;
diff --git a/src/lib/krb5/krb/s4u_authdata.c b/src/lib/krb5/krb/s4u_authdata.c
index d93e758..5b4704b 100644
--- a/src/lib/krb5/krb/s4u_authdata.c
+++ b/src/lib/krb5/krb/s4u_authdata.c
@@ -165,7 +165,7 @@ s4u2proxy_export_authdata(krb5_context kcontext,
memset(&sp, 0, sizeof(sp));
sp.delegated = s4uctx->delegated;
- authdata = k5alloc(2 * sizeof(krb5_authdata *), &code);
+ authdata = k5calloc(2, sizeof(krb5_authdata *), &code);
if (authdata == NULL)
return code;
@@ -253,7 +253,7 @@ s4u2proxy_get_attribute_types(krb5_context kcontext,
if (s4uctx->count == 0)
return ENOENT;
- attrs = k5alloc(2 * sizeof(krb5_data), &code);
+ attrs = k5calloc(2, sizeof(krb5_data), &code);
if (attrs == NULL)
goto cleanup;
@@ -379,7 +379,7 @@ s4u2proxy_export_internal(krb5_context kcontext,
if (restrict_authenticated)
return ENOENT;
- delegated = k5alloc((s4uctx->count + 1) * sizeof(krb5_principal), &code);
+ delegated = k5calloc(s4uctx->count + 1, sizeof(krb5_principal), &code);
if (delegated == NULL)
return code;
@@ -511,7 +511,7 @@ s4u2proxy_internalize(krb5_context kcontext,
else if (count > 0) {
int i;
- delegated = k5alloc((count + 1) * sizeof(krb5_principal), &code);
+ delegated = k5calloc(count + 1, sizeof(krb5_principal), &code);
if (delegated == NULL)
goto cleanup;
diff --git a/src/lib/krb5/krb/send_tgs.c b/src/lib/krb5/krb/send_tgs.c
index 9a7c261..cd56366 100644
--- a/src/lib/krb5/krb/send_tgs.c
+++ b/src/lib/krb5/krb/send_tgs.c
@@ -232,7 +232,7 @@ k5_make_tgs_req(krb5_context context,
for (count = 0; in_padata != NULL && in_padata[count] != NULL; count++);
/* Construct a padata array for the request, beginning with the ap-req. */
- padata = k5alloc((count + 2) * sizeof(krb5_pa_data *), &ret);
+ padata = k5calloc(count + 2, sizeof(krb5_pa_data *), &ret);
if (padata == NULL)
goto cleanup;
padata[0] = k5alloc(sizeof(krb5_pa_data), &ret);
diff --git a/src/lib/krb5/os/expand_path.c b/src/lib/krb5/os/expand_path.c
index 3d23849..f14e9ac 100644
--- a/src/lib/krb5/os/expand_path.c
+++ b/src/lib/krb5/os/expand_path.c
@@ -477,7 +477,7 @@ k5_expand_path_tokens_extra(krb5_context context, const char *path_in,
/* Get extra tokens. */
if (nargs > 0) {
- extra_tokens = k5alloc((nargs + 1) * sizeof(char *), &ret);
+ extra_tokens = k5calloc(nargs + 1, sizeof(char *), &ret);
if (extra_tokens == NULL)
goto cleanup;
va_start(ap, path_out);
diff --git a/src/lib/krb5/os/localauth.c b/src/lib/krb5/os/localauth.c
index 82fc1f9..81ab5d8 100644
--- a/src/lib/krb5/os/localauth.c
+++ b/src/lib/krb5/os/localauth.c
@@ -155,7 +155,7 @@ load_localauth_modules(krb5_context context)
/* Allocate a large enough list of handles. */
for (count = 0; modules[count] != NULL; count++);
- list = k5alloc((count + 1) * sizeof(*list), &ret);
+ list = k5calloc(count + 1, sizeof(*list), &ret);
if (list == NULL)
goto cleanup;
diff --git a/src/plugins/kdb/hdb/kdb_marshal.c b/src/plugins/kdb/hdb/kdb_marshal.c
index 3b2878a..b6a7dc4 100644
--- a/src/plugins/kdb/hdb/kdb_marshal.c
+++ b/src/plugins/kdb/hdb/kdb_marshal.c
@@ -187,9 +187,9 @@ kh_marshal_Principal(krb5_context context,
return code;
hprinc->name.name_type = kprinc->type;
- hprinc->name.name_string.val = k5alloc(kprinc->length *
- sizeof(heim_general_string),
- &code);
+ hprinc->name.name_string.val = k5calloc(kprinc->length,
+ sizeof(heim_general_string),
+ &code);
if (code != 0) {
kh_free_Principal(context, hprinc);
return code;
@@ -229,8 +229,8 @@ kh_unmarshal_Principal(krb5_context context,
kprinc->magic = KV5M_PRINCIPAL;
kprinc->type = hprinc->name.name_type;
- kprinc->data = k5alloc(hprinc->name.name_string.len * sizeof(krb5_data),
- &code);
+ kprinc->data = k5calloc(hprinc->name.name_string.len, sizeof(krb5_data),
+ &code);
if (code != 0) {
krb5_free_principal(context, kprinc);
return code;
@@ -594,7 +594,8 @@ kh_marshal_HDB_extensions(krb5_context context,
unsigned int i;
krb5_error_code code;
- hexts->val = k5alloc(kh_hdb_extension_count * sizeof(HDB_extension), &code);
+ hexts->val = k5calloc(kh_hdb_extension_count, sizeof(HDB_extension),
+ &code);
if (code != 0)
return code;
@@ -704,7 +705,7 @@ kh_marshal_hdb_entry(krb5_context context,
goto cleanup;
hentry->keys.len = 0;
- hentry->keys.val = k5alloc(kentry->n_key_data * sizeof(Key), &code);
+ hentry->keys.val = k5calloc(kentry->n_key_data, sizeof(Key), &code);
if (code != 0)
goto cleanup;
@@ -788,7 +789,8 @@ kh_unmarshal_hdb_entry(krb5_context context,
if (code != 0)
goto cleanup;
- kentry->key_data = k5alloc(hentry->keys.len * sizeof(krb5_key_data), &code);
+ kentry->key_data = k5calloc(hentry->keys.len, sizeof(krb5_key_data),
+ &code);
if (code != 0)
goto cleanup;
diff --git a/src/plugins/kdb/hdb/kdb_windc.c b/src/plugins/kdb/hdb/kdb_windc.c
index bb07f4c..48140a5 100644
--- a/src/plugins/kdb/hdb/kdb_windc.c
+++ b/src/plugins/kdb/hdb/kdb_windc.c
@@ -342,7 +342,7 @@ kh_db_sign_auth_data(krb5_context context,
goto cleanup;
if (authdata == NULL) {
- authdata = k5alloc(2 * sizeof(krb5_authdata *), &code);
+ authdata = k5calloc(2, sizeof(krb5_authdata *), &code);
if (code != 0)
goto cleanup;
@@ -461,7 +461,7 @@ kh_marshall_HostAddresses(krb5_context context,
return code;
haddresses->len = 0;
- haddresses->val = k5alloc(i * sizeof(HostAddress), &code);
+ haddresses->val = k5calloc(i, sizeof(HostAddress), &code);
if (code != 0)
return code;
diff --git a/src/plugins/preauth/otp/otp_state.c b/src/plugins/preauth/otp/otp_state.c
index f2a64a4..a4d7e3b 100644
--- a/src/plugins/preauth/otp/otp_state.c
+++ b/src/plugins/preauth/otp/otp_state.c
@@ -293,7 +293,7 @@ token_types_decode(profile_t profile, token_type **out)
}
/* Leave space for the default (possibly) and the terminator. */
- types = k5alloc((i + 2) * sizeof(token_type), &retval);
+ types = k5calloc(i + 2, sizeof(token_type), &retval);
if (types == NULL)
goto cleanup;
@@ -441,7 +441,7 @@ tokens_decode(krb5_context ctx, krb5_const_principal princ,
return retval;
len = k5_json_array_length(arr);
- tokens = k5alloc((len + 1) * sizeof(token), &retval);
+ tokens = k5calloc(len + 1, sizeof(token), &retval);
if (tokens == NULL)
goto cleanup;
More information about the cvs-krb5
mailing list