From 38cf8dd1a5f4cb2f23af642e8a2f52d1ef2a6d29 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Tue, 13 Oct 2026 19:25:08 +0000 Subject: [PATCH] cangw: fix NULL pointer dereference in modification parsing parse_mod() and parse_fdmod() did not check the return value of strchr() when looking for the ':' delimiters. A modification definition without ':' (e.g. '-m AND') led to a segmentation fault. Add the missing NULL pointer checks. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Oliver Hartkopp --- cangw.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cangw.c b/cangw.c index f99a956..9cfa5b9 100644 --- a/cangw.c +++ b/cangw.c @@ -338,7 +338,7 @@ static int parse_mod(char *optarg, struct modattr *modmsg) ptr = optarg; nptr = strchr(ptr, ':'); - if ((nptr - ptr > 3) || (nptr - ptr == 0)) + if (!nptr || (nptr - ptr > 3) || (nptr - ptr == 0)) return 1; if (!strncmp(ptr, "AND", 3)) @@ -355,7 +355,7 @@ static int parse_mod(char *optarg, struct modattr *modmsg) ptr = nptr+1; nptr = strchr(ptr, ':'); - if ((nptr - ptr > 3) || (nptr - ptr == 0)) + if (!nptr || (nptr - ptr > 3) || (nptr - ptr == 0)) return 3; modmsg->modtype = 0; @@ -406,7 +406,7 @@ static int parse_fdmod(char *optarg, struct fdmodattr *modmsg) ptr = optarg; nptr = strchr(ptr, ':'); - if ((nptr - ptr > 3) || (nptr - ptr == 0)) + if (!nptr || (nptr - ptr > 3) || (nptr - ptr == 0)) return 1; if (!strncmp(ptr, "AND", 3)) @@ -423,7 +423,7 @@ static int parse_fdmod(char *optarg, struct fdmodattr *modmsg) ptr = nptr+1; nptr = strchr(ptr, ':'); - if ((nptr - ptr > 4) || (nptr - ptr == 0)) + if (!nptr || (nptr - ptr > 4) || (nptr - ptr == 0)) return 3; modmsg->modtype = 0;