]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps: use app_malloc_array()
authorEugene Syromiatnikov <esyr@openssl.org>
Thu, 4 Sep 2025 15:59:33 +0000 (17:59 +0200)
committerNeil Horman <nhorman@openssl.org>
Sun, 7 Sep 2025 11:22:24 +0000 (07:22 -0400)
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)

apps/ca.c
apps/ecparam.c
apps/lib/apps.c
apps/lib/http_server.c
apps/lib/s_cb.c
apps/rsautl.c
apps/speed.c
apps/srp.c

index de3d5669de46d0f3fd78769a02afb4fe2e3b35cf..a356b53b725e8b789dae00cf48152717c8b5fafe 100644 (file)
--- 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;
index f0879dfb11a9f12edffb718e1a6c8a99dc8ca614..b025e9bc75029fd51e083b0157124f5264a38423 100644 (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++) {
index 2cd2541cce841b5851612d8fa7dac90159c2a32c..14fb097e13a07cd280c2abe6360274dbdf8f7771 100644 (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;
index 8136228b32d0ff9ab7927624e7da80af6b2a2614..82befa188f7a3d1dedeaff22c34b36a0880b0c15 100644 (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;
 
index 8e6f50d537959af641d39152cb6d0c93478289b4..496cb3c6f1684f78f4eb4debf8884c31a679c752 100644 (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: ");
index f652d345f6202a5e1b118d0bb83445ad34ab5ac7..db11e3498f3a87b870b6a056e10ad7cf11ada5d3 100644 (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;
 
index 059183ddc77d3b38ff86bc080d0645f84527d654..2eb8ee3b6008ab1fee4895c70ced5bcec2560f35 100644 (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");
index a9466f830289b018af5267d0ea2de9b310730cd3..4e8f226503809a971cc85e4a91e07b7748a6fa7f 100644 (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;