xshared: Fix parsing of empty string arg in '-c' option
Phil Sutter
reviewerPATCH 1/1 xshared: Fix parsing of empty string arg in '-c' option
Calling iptables with '-c ""' resulted in a call to strchr() with an invalid pointer as 'optarg + 1' points to past the buffer. The most simple fix is to drop the offset: The global optstring part specifies a single colon after 'c', so getopt() enforces a valid pointer in optarg. If it contains a comma at first position, packet counter value parsing will fail so all cases are covered.
--- extensions/iptables.t | 5 +++++ iptables/xshared.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
extensions/iptables.t +5 -0
@@ -4,3 +4,8 @@ -i eth+ -o alongifacename+;=;OK ! -i eth0;=;OK ! -o eth+;=;OK +-c "";;FAIL +-c ,3;;FAIL +-c 3,;;FAIL +-c ,;;FAIL +-c 2,3 -j ACCEPT;-j ACCEPT;OK
iptables/xshared.c +1 -1
@@ -1885,7 +1885,7 @@ void do_parse(int argc, char *argv[],set_option (p->ops, &cs->options,OPT_COUNTERS , &args->invflags, invert); args->pcnt = optarg; - args->bcnt =strchr (args->pcnt +1 ,',' ); + args->bcnt =strchr (args->pcnt,',' );if (args->bcnt) args->bcnt++;if (!args->bcnt &&xs_has_arg (argc, argv))
Signature · 1 line
2.43.0
Phil Sutter
reviewerQuoted 11 lines · Phil Sutter
Calling iptables with '-c ""' resulted in a call to
strchr()with an invalid pointer as 'optarg + 1' points to past the buffer. The most simple fix is to drop the offset: The global optstring part specifies a single colon after 'c', sogetopt()enforces a valid pointer in optarg. If it contains a comma at first position, packet counter value parsing will fail so all cases are covered.Reported-by [email protected]Fixes 60a6073690a45 ("Make --set-counters (-c) accept comma separated counters")Signed-off-by Phil Sutter <[email protected]>
Patch applied.