Skip to content

Commit

Permalink
Use k5calloc instead of k5alloc where appropriate
Browse files Browse the repository at this point in the history
Wherever we use k5alloc with a multiplication in the size parameter,,
use the new k5calloc helper function instead.
  • Loading branch information
greghudson committed Jul 12, 2013
1 parent 90f9f6f commit 443ce5f
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/kdc/kdc_authdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/kdc/kdc_preauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/builtin/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/krb/cf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/krb/checksum_confounder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/krb/checksum_hmac_md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/krb/combine_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/kadm5/srv/kadm5_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/kadm5/srv/pwqual.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/kadm5/srv/server_kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/ccache/ccselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/krb/preauth_encts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions src/lib/krb5/krb/s4u_authdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/krb/send_tgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/os/expand_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/os/localauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 10 additions & 8 deletions src/plugins/kdb/hdb/kdb_marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/kdb/hdb/kdb_windc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/preauth/otp/otp_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 443ce5f

Please sign in to comment.