Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3a4d05

Browse files
esyrnhorman
authored andcommitted
apps, fuzz, providers: use array memory (re)allocation routines
Co-Authored-by: Alexandr Nedvedicky <[email protected]> Signed-off-by: Eugene Syromiatnikov <[email protected]> Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Neil Horman <[email protected]> (Merged from #28059)
1 parent 5fab189 commit f3a4d05

7 files changed

Lines changed: 12 additions & 13 deletions

File tree

apps/lib/apps.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ int chopup_args(ARGS *arg, char *buf)
106106
char **tmp;
107107

108108
arg->size += 20;
109-
tmp = OPENSSL_realloc(arg->argv, sizeof(*arg->argv) * arg->size);
109+
tmp = OPENSSL_realloc_array(arg->argv,
110+
arg->size, sizeof(*arg->argv));
110111
if (tmp == NULL)
111112
return 0;
112113
arg->argv = tmp;
@@ -3461,7 +3462,7 @@ OSSL_PARAM *app_params_new_from_opts(STACK_OF(OPENSSL_STRING) *opts,
34613462
if (opts == NULL)
34623463
return NULL;
34633464

3464-
params = OPENSSL_zalloc(sizeof(OSSL_PARAM) * (sz + 1));
3465+
params = OPENSSL_calloc(sz + 1, sizeof(OSSL_PARAM));
34653466
if (params == NULL)
34663467
return NULL;
34673468

apps/lib/vms_decc_argv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ char **copy_argv(int *argc, char *argv[])
5656
* get them when linking with all of libapps.a.
5757
* See comment in test/build.info.
5858
*/
59-
newargv = OPENSSL_malloc(sizeof(*newargv) * (count + 1));
59+
newargv = OPENSSL_malloc_array(count + 1, sizeof(*newargv));
6060
if (newargv == NULL)
6161
return NULL;
6262

apps/x509.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ static int print_x509v3_exts(BIO *bio, X509 *x, const char *ext_names)
13031303
BIO_printf(bio, "Invalid extension names: %s\n", ext_names);
13041304
goto end;
13051305
}
1306-
if ((names = OPENSSL_malloc(sizeof(char *) * nn)) == NULL)
1306+
if ((names = OPENSSL_malloc_array(nn, sizeof(char *))) == NULL)
13071307
goto end;
13081308
parse_ext_names(tmp_ext_names, names);
13091309

fuzz/hashtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int FuzzerInitialize(int *argc, char ***argv)
103103

104104
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
105105
ERR_clear_error();
106-
prediction_table = OPENSSL_zalloc(sizeof(FUZZER_VALUE) * 65537);
106+
prediction_table = OPENSSL_calloc(65537, sizeof(FUZZER_VALUE));
107107
if (prediction_table == NULL)
108108
return -1;
109109
fuzzer_table = ossl_ht_new(&fuzz_conf);

fuzz/provider.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static OSSL_PARAM *fuzz_params(OSSL_PARAM *param, const uint8_t **buf, size_t *l
270270
for (p = param; p != NULL && p->key != NULL; p++)
271271
p_num++;
272272

273-
fuzzed_parameters = OPENSSL_zalloc(sizeof(OSSL_PARAM) *(p_num + 1));
273+
fuzzed_parameters = OPENSSL_calloc(p_num + 1, sizeof(OSSL_PARAM));
274274
p = fuzzed_parameters;
275275

276276
for (; param != NULL && param->key != NULL; param++) {

providers/implementations/encode_decode/ml_common_codecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ossl_ml_common_pkcs8_fmt_order(const char *algorithm_name,
4242
const char *sep = "\t ,";
4343

4444
/* Reserve an extra terminal slot with fmt == NULL */
45-
if ((ret = OPENSSL_zalloc((NUM_PKCS8_FORMATS + 1) * sizeof(*ret))) == NULL)
45+
if ((ret = OPENSSL_calloc(NUM_PKCS8_FORMATS + 1, sizeof(*ret))) == NULL)
4646
return NULL;
4747

4848
/* Entries that match a format will get a non-zero preference. */

providers/implementations/kdfs/argon2.c.in

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,8 @@ static int fill_mem_blocks_mt(KDF_ARGON2 *ctx)
569569
void **t;
570570
ARGON2_THREAD_DATA *t_data;
571571

572-
t = OPENSSL_zalloc(sizeof(void *)*ctx->lanes);
573-
t_data = OPENSSL_zalloc(ctx->lanes * sizeof(ARGON2_THREAD_DATA));
572+
t = OPENSSL_calloc(ctx->lanes, sizeof(void *));
573+
t_data = OPENSSL_calloc(ctx->lanes, sizeof(ARGON2_THREAD_DATA));
574574

575575
if (t == NULL || t_data == NULL)
576576
goto fail;
@@ -738,11 +738,9 @@ static int initialize(KDF_ARGON2 *ctx)
738738
return 0;
739739

740740
if (ctx->type != ARGON2_D)
741-
ctx->memory = OPENSSL_secure_zalloc(ctx->memory_blocks *
742-
sizeof(BLOCK));
741+
ctx->memory = OPENSSL_secure_calloc(ctx->memory_blocks, sizeof(BLOCK));
743742
else
744-
ctx->memory = OPENSSL_zalloc(ctx->memory_blocks *
745-
sizeof(BLOCK));
743+
ctx->memory = OPENSSL_calloc(ctx->memory_blocks, sizeof(BLOCK));
746744

747745
if (ctx->memory == NULL) {
748746
ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MEMORY_SIZE,

0 commit comments

Comments
 (0)