]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdtab: Add value assert in fmap_xchg
authorAndrei Tatar <andrei@unikraft.io>
Tue, 23 Jan 2024 18:37:36 +0000 (19:37 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Sun, 23 Feb 2025 10:29:25 +0000 (10:29 +0000)
This change adds an assert to sanity-check the value to be exchanged
into the fmap. Exchanging in a NULL value is an invalid operation and
breaks the semantics of fmap, leaving the data structure in a
potentially unsound state.
Calling code should never normally do this; the assert serves as extra
precaution for future development.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1278

lib/posix-fdtab/fmap.h

index da1d0056baec856a38f37d5c91127c76b37f497f..66e796c5471e8db9615a282f8e9ae1faf6afe1d7 100644 (file)
@@ -385,6 +385,7 @@ int uk_fmap_xchg(const struct uk_fmap *m, int idx,
 {
        void *got;
 
+       UK_ASSERT(p); /* Cannot exchange with NULL, use uk_fmap_take instead */
        if (!_FMAP_INRANGE(m, idx))
                return -1;