[PATCH 6/6] alfred: validate the IPv4 multicast group argument
Sven Eckelmann <[email protected]> Thu, 30 Jul 2026 21:32:00 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
The return value of inet_pton() was ignored when parsing the -4
option. A mistyped group address left alfred_mcast untouched, so the
daemon continued with the first bytes of the IPv6 default group
(255.2.0.0) as IPv4 multicast group. Instead of a clear parse error
the user only got confusing 'can't add multicast membership' failures
at runtime.
Reject the option argument when it is not a valid IPv4 address.
Fixes: c7da798113a2 ("alfred: IPv4 multicast distribution support.")
Signed-off-by: Sven Eckelmann <[email protected]>
---
main.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/main.c b/main.c
index 6372ec8..3953020 100644
--- a/main.c
+++ b/main.c
@@ -330,7 +330,11 @@ static struct globals *alfred_init(int argc, char *argv[])
break;
case '4':
globals->ipv4mode = true;
- inet_pton(AF_INET, optarg, &alfred_mcast.ipv4);
+ ret = inet_pton(AF_INET, optarg, &alfred_mcast.ipv4);
+ if (ret != 1) {
+ fprintf(stderr, "bad IPv4 multicast group argument\n");
+ return NULL;
+ }
printf(" ** IPv4 Multicast Mode: %x\n", alfred_mcast.ipv4.s_addr);
break;
case 'f':
--
2.47.3