apps: use app_malloc_array()

Replace app_malloc() calls where app_malloc_array() ones where
appropriate.

Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28444)
This commit is contained in:
Eugene Syromiatnikov 2025-09-04 17:59:33 +02:00 committed by Neil Horman
parent 4f288b60e8
commit ddee212bab
8 changed files with 11 additions and 10 deletions

View File

@ -1916,7 +1916,7 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
goto end;
}
irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row space");
irow = app_malloc_array(DB_NUMBER + 1, sizeof(*irow), "row space");
for (i = 0; i < DB_NUMBER; i++)
irow[i] = row[i];
irow[DB_NUMBER] = NULL;
@ -2145,7 +2145,7 @@ static int do_revoke(X509 *x509, CA_DB *db, REVINFO_TYPE rev_type,
goto end;
}
irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row ptr");
irow = app_malloc_array(DB_NUMBER + 1, sizeof(*irow), "row ptr");
for (i = 0; i < DB_NUMBER; i++)
irow[i] = row[i];
irow[DB_NUMBER] = NULL;

View File

@ -70,7 +70,7 @@ static int list_builtin_curves(BIO *out)
EC_builtin_curve *curves = NULL;
size_t n, crv_len = EC_get_builtin_curves(NULL, 0);
curves = app_malloc((int)sizeof(*curves) * crv_len, "list curves");
curves = app_malloc_array(crv_len, sizeof(*curves), "list curves");
EC_get_builtin_curves(curves, crv_len);
for (n = 0; n < crv_len; n++) {

View File

@ -3297,7 +3297,7 @@ void wait_for_async(SSL *s)
return;
if (numfds == 0)
return;
fds = app_malloc(sizeof(OSSL_ASYNC_FD) * numfds, "allocate async fds");
fds = app_malloc_array(numfds, sizeof(*fds), "allocate async fds");
if (!SSL_get_all_async_fds(s, fds, &numfds)) {
OPENSSL_free(fds);
return;

View File

@ -92,7 +92,8 @@ void spawn_loop(const char *prog)
strerror(errno));
exit(1);
}
kidpids = app_malloc(n_responders * sizeof(*kidpids), "child PID array");
kidpids = app_malloc_array(n_responders, sizeof(*kidpids),
"child PID array");
for (i = 0; i < n_responders; ++i)
kidpids[i] = 0;

View File

@ -391,7 +391,7 @@ int ssl_print_groups(BIO *out, SSL *s, int noshared)
ngroups = SSL_get1_groups(s, NULL);
if (ngroups <= 0)
return 1;
groups = app_malloc(ngroups * sizeof(int), "groups to print");
groups = app_malloc_array(ngroups, sizeof(*groups), "groups to print");
SSL_get1_groups(s, groups);
BIO_puts(out, "Supported groups: ");

View File

@ -215,7 +215,7 @@ int rsautl_main(int argc, char **argv)
keysize = EVP_PKEY_get_size(pkey);
rsa_in = app_malloc(keysize * 2, "hold rsa key");
rsa_in = app_malloc_array(2, keysize, "hold rsa key");
rsa_out = app_malloc(keysize, "output rsa key");
rsa_outlen = keysize;

View File

@ -2499,7 +2499,7 @@ int speed_main(int argc, char **argv)
loopargs_len = (async_jobs == 0 ? 1 : async_jobs);
loopargs =
app_malloc(loopargs_len * sizeof(loopargs_t), "array of loopargs");
app_malloc_array(loopargs_len, sizeof(loopargs_t), "array of loopargs");
memset(loopargs, 0, loopargs_len * sizeof(loopargs_t));
buflen = lengths[size_num - 1];
@ -4885,7 +4885,7 @@ static int do_multi(int multi, int size_num)
int status;
static char sep[] = ":";
fds = app_malloc(sizeof(*fds) * multi, "fd buffer for do_multi");
fds = app_malloc_array(multi, sizeof(*fds), "fd buffer for do_multi");
for (n = 0; n < multi; ++n) {
if (pipe(fd) == -1) {
BIO_printf(bio_err, "pipe failure\n");

View File

@ -97,7 +97,7 @@ static int update_index(CA_DB *db, char **row)
char **irow;
int i;
irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
irow = app_malloc_array(DB_NUMBER + 1, sizeof(*irow), "row pointers");
for (i = 0; i < DB_NUMBER; i++)
irow[i] = row[i];
irow[DB_NUMBER] = NULL;