[PATCH 3/6] alfred: check strdup() failures during option parsing
Sven Eckelmann <[email protected]> Thu, 30 Jul 2026 21:31:57 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
alfred_init() duplicates the default batman-adv interface name and the interface names passed via -i/-I and -b/-B with strdup() but never checked the result. On allocation failure globals->mesh_iface or globals->net_iface is left NULL and later used unconditionally and crashes. The allocation should be checked to present a user readable error instead of crashing at a later point. Signed-off-by: Sven Eckelmann <[email protected]> --- main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.c b/main.c index cc3bc42..baedbd2 100644 --- a/main.c +++ b/main.c @@ -262,6 +262,10 @@ static struct globals *alfred_init(int argc, char *argv[]) case 'i': free(globals->net_iface); globals->net_iface = strdup(optarg); + if (!globals->net_iface) { + perror("strdup"); + return NULL; + } break; case 'B': globals->clientmode = CLIENT_CHANGE_BAT_IFACE; @@ -269,6 +273,10 @@ static struct globals *alfred_init(int argc, char *argv[]) case 'b': free(globals->mesh_iface); globals->mesh_iface = strdup(optarg); + if (!globals->mesh_iface) { + perror("strdup"); + return NULL; + } break; case 'S': globals->clientmode = CLIENT_SERVER_STATUS; -- 2.47.3