]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tdbtorture: Fix CID 1034815,1034816: protect from out-of-bounds access
authorShachar Sharon <ssharon@redhat.com>
Mon, 8 Sep 2025 05:19:23 +0000 (08:19 +0300)
committerAnoop C S <anoopcs@samba.org>
Thu, 11 Sep 2025 19:06:16 +0000 (19:06 +0000)
A user may provide a non-valid input value for 'num_procs' (negative).
Avoid potential out-of-bound access by forcing 'unsigned int' value
(Coverity: OVERRUN).

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Anoop C S <anoopcs@samba.org>
Autobuild-Date(master): Thu Sep 11 19:06:16 UTC 2025 on atb-devel-224

lib/tdb/tools/tdbtorture.c

index 14dc5e7a8d1102b2888ad0cc19823f4f9096bd7e..cf9fdfbbe10936b1544dd8676a6d9af79ac2481b 100644 (file)
@@ -314,7 +314,7 @@ int main(int argc, char * const *argv)
 {
        int i, seed = -1;
        int num_loops = 5000;
-       int num_procs = 3;
+       unsigned num_procs = 3;
        int c, pfds[2];
        extern char *optarg;
        pid_t *pids;
@@ -327,7 +327,7 @@ int main(int argc, char * const *argv)
        while ((c = getopt(argc, argv, "n:l:s:H:thkm")) != -1) {
                switch (c) {
                case 'n':
-                       num_procs = strtol(optarg, NULL, 0);
+                       num_procs = strtoul(optarg, NULL, 0);
                        break;
                case 'l':
                        num_loops = strtol(optarg, NULL, 0);
@@ -364,7 +364,7 @@ int main(int argc, char * const *argv)
                seed = (getpid() + time(NULL)) & 0x7FFFFFFF;
        }
 
-       printf("Testing with %d processes, %d loops, %d hash_size, seed=%d%s\n",
+       printf("Testing with %u processes, %d loops, %d hash_size, seed=%d%s\n",
               num_procs, num_loops, hash_size, seed,
               (always_transaction ? " (all within transactions)" : ""));