From a0751085a8b79e5666ce53aa11ad0ff97fdf7e07 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 10 Feb 2026 17:35:28 +0100 Subject: [PATCH] client: Fix issue with const return value from strrchr When compiling iwd with recent gcc and glibc-2.43 the --Wdiscarded-qualifiers warning occurs because with ISO C23, the function strrrchr that return pointers into their input arrays now have definitions as macros that return a pointer to a const-qualified type when the input argument is a pointer to a const-qualified type. client/known-networks.c: In function 'known_network_proxy_find_by_name': client/known-networks.c:296:29: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 296 | char *dot = strrchr(name, '.'); | ^~~~~~~ The warning hints to real bug since *dot should not be modified since *name is actually const to begin with. Change the code to utilize a copy of the name value if needed. Reported-by: Rudi Heitbaum --- client/known-networks.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/client/known-networks.c b/client/known-networks.c index 8634aca2..f9063786 100644 --- a/client/known-networks.c +++ b/client/known-networks.c @@ -279,35 +279,35 @@ static const struct proxy_interface *known_network_proxy_find_by_name( struct network_args network_args; struct l_queue *match; const struct proxy_interface *proxy; + size_t name_len; + char *args_name; if (!name) return NULL; - if (l_str_has_suffix(name, ".psk")) + name_len = strlen(name); + + if (l_str_has_suffix(name, ".psk")) { network_args.type = "psk"; - else if (l_str_has_suffix(name, ".8021x")) + name_len -= 4; + } else if (l_str_has_suffix(name, ".8021x")) { network_args.type = "8021x"; - else if (l_str_has_suffix(name, ".open")) + name_len -= 6; + } else if (l_str_has_suffix(name, ".open")) { network_args.type = "open"; - else + name_len -= 5; + } else network_args.type = NULL; - if (network_args.type) { - char *dot = strrchr(name, '.'); - - if (!dot) - /* This shouldn't ever be the case */ - return NULL; - - *dot = '\0'; - } - - network_args.name = name; + args_name = l_strndup(name, name_len); + network_args.name = args_name; match = proxy_interface_find_all(known_network_interface_type.interface, known_network_match, &network_args); + l_free(args_name); + if (!match) { display("No network with specified parameters was found\n"); return NULL;