]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cpu-set-util: add asserts to guide static analysis after realloc
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 19:49:20 +0000 (19:49 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 19:56:31 +0000 (19:56 +0000)
Coverity flags CPU_SET_S() calls as potential out-of-bounds writes
because it cannot trace that cpu_set_realloc() guarantees the
allocated buffer is large enough for the given index. Add asserts
to make the size invariant explicit.

CID#1611787
CID#1611788

Follow-up for 0985c7c4e22c8dbbea4398cf3453da45ebf63800

src/shared/cpu-set-util.c

index e4ef36da9aaba4fb4fb905164595f8a9b43dcdab..9211dbe47e54a46e8b03a26ab3ec4cb4a85db3b3 100644 (file)
@@ -159,6 +159,8 @@ int cpu_set_add(CPUSet *c, size_t i) {
         if (r < 0)
                 return r;
 
+        /* Silence static analyzers */
+        assert(i / CHAR_BIT < c->allocated);
         CPU_SET_S(i, c->allocated, c->set);
         return 0;
 }
@@ -194,6 +196,8 @@ int cpu_set_add_range(CPUSet *c, size_t start, size_t end) {
         if (r < 0)
                 return r;
 
+        /* Silence static analyzers */
+        assert(end / CHAR_BIT < c->allocated);
         for (size_t i = start; i <= end; i++)
                 CPU_SET_S(i, c->allocated, c->set);