From: Eugene Syromiatnikov Date: Thu, 4 Sep 2025 15:59:33 +0000 (+0200) Subject: apps: use app_malloc_array() X-Git-Tag: 4.0-PRE-CLANG-FORMAT-WEBKIT~558 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddee212babd9f6cc40ac72d5eb084db80fc6e370;p=thirdparty%2Fopenssl.git apps: use app_malloc_array() Replace app_malloc() calls where app_malloc_array() ones where appropriate. Signed-off-by: Eugene Syromiatnikov Reviewed-by: Paul Dale Reviewed-by: Dmitry Belyavskiy Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28444) --- diff --git a/apps/ca.c b/apps/ca.c index de3d5669de4..a356b53b725 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -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; diff --git a/apps/ecparam.c b/apps/ecparam.c index f0879dfb11a..b025e9bc750 100644 --- a/apps/ecparam.c +++ b/apps/ecparam.c @@ -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++) { diff --git a/apps/lib/apps.c b/apps/lib/apps.c index 2cd2541cce8..14fb097e13a 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -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; diff --git a/apps/lib/http_server.c b/apps/lib/http_server.c index 8136228b32d..82befa188f7 100644 --- a/apps/lib/http_server.c +++ b/apps/lib/http_server.c @@ -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; diff --git a/apps/lib/s_cb.c b/apps/lib/s_cb.c index 8e6f50d5379..496cb3c6f16 100644 --- a/apps/lib/s_cb.c +++ b/apps/lib/s_cb.c @@ -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: "); diff --git a/apps/rsautl.c b/apps/rsautl.c index f652d345f62..db11e3498f3 100644 --- a/apps/rsautl.c +++ b/apps/rsautl.c @@ -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; diff --git a/apps/speed.c b/apps/speed.c index 059183ddc77..2eb8ee3b600 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -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"); diff --git a/apps/srp.c b/apps/srp.c index a9466f83028..4e8f2265038 100644 --- a/apps/srp.c +++ b/apps/srp.c @@ -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;