]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Fix bitmap_talloc()'s parameter to unsigned
authorVolker Lendecke <vl@samba.org>
Wed, 29 Oct 2025 12:41:30 +0000 (13:41 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 10 Nov 2025 13:29:30 +0000 (13:29 +0000)
It does not make sense to allocate a negative number of bits

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
lib/util/bitmap.c
lib/util/bitmap.h

index 12cdfe4d16a4becce3ac26090e11cd40c5149820..82cf55e459aa28cdca827317213a50d2aab76d39 100644 (file)
@@ -34,10 +34,14 @@ struct bitmap {
 /****************************************************************************
 talloc a bitmap
 ****************************************************************************/
-struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, int n)
+struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, unsigned n)
 {
        struct bitmap *bm;
 
+       if (n > (UINT_MAX - 32)) {
+               return NULL;
+       }
+
        bm = (struct bitmap *)talloc_zero_size(
                mem_ctx,
                offsetof(struct bitmap, b) + sizeof(uint32_t)*((n+31)/32));
index 6d75929fb5a6df155697023990af44d14765947f..be6d028c186cb10b640211e004b3e7fb23600be8 100644 (file)
@@ -21,7 +21,7 @@
 
 struct bitmap;
 
-struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, int n);
+struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, unsigned n);
 int bitmap_copy(struct bitmap * const dst, const struct bitmap * const src);
 bool bitmap_set(struct bitmap *bm, unsigned i);
 bool bitmap_clear(struct bitmap *bm, unsigned i);