]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
lib: ipset: Avoid 'argv' array overstepping
authorPhil Sutter <phil@nwl.cc>
Thu, 27 Jun 2024 08:18:17 +0000 (10:18 +0200)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Thu, 27 Jun 2024 13:54:27 +0000 (15:54 +0200)
The maximum accepted value for 'argc' is MAX_ARGS which matches 'argv'
array size. The maximum allowed array index is therefore argc-1.

This fix will leave items in argv non-NULL-terminated, so explicitly
NULL the formerly last entry after shifting.

Looks like a day-1 bug. Interestingly, this neither triggered ASAN nor
valgrind. Yet adding debug output printing argv entries being copied
did.

Fixes: 1e6e8bd9a62aa ("Third stage to ipset-5")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
lib/ipset.c

index c910d88805c288af314164f6f53432d1c04bd25a..3bf1c5fcdbc59595eebaf0cdac209002a5fa7bcd 100644 (file)
@@ -343,9 +343,9 @@ ipset_shift_argv(int *argc, char *argv[], int from)
 
        assert(*argc >= from + 1);
 
-       for (i = from + 1; i <= *argc; i++)
+       for (i = from + 1; i < *argc; i++)
                argv[i-1] = argv[i];
-       (*argc)--;
+       argv[--(*argc)] = NULL;
        return;
 }