[PATCH] Fix modification of read-only string
Marc Dionne
marc.dionne at auristor.com
Tue Feb 3 05:09:47 PST 2026
On Tue, Feb 3, 2026 at 5:03 AM David Howells <dhowells at redhat.com> wrote:
>
> In cellserv_parse_address(), when parsing an IPv6 address bounded by
> "[...]", it searches the const string for the closing ']' and then modifies
> the string to end it at the ']' position. This previously compiled fine
> because strchr() got rid of the const, however in Fedora 44 this is now
> detected by the compiler.
>
> Fix this by constructing the desired string in a stack buffer.
>
> Signed-off-by: David Howells <dhowells at redhat.com>
> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2434693
> ---
> src/lib_cellserv.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib_cellserv.c b/src/lib_cellserv.c
> index 1419532..1debec0 100644
> --- a/src/lib_cellserv.c
> +++ b/src/lib_cellserv.c
> @@ -66,13 +66,17 @@ static int cellserv_parse_address(const struct kafs_profile *child,
> }
>
> if (v[0] == '[') {
> - char *p;
> + char *p, *q;
I think you want to make 'p' a const char *.
>
> v++;
> p = strchr(v, ']');
Otherwise this generates an "assignment discards ‘const’ qualifier
from pointer target type" error.
> if (!p || p[1])
> goto invalid;
> - p[0] = 0;
> +
> + q = alloca(p - v + 1);
> + memcpy(q, v, p - v);
> + q[p - v] = 0;
> + v = q;
> }
>
> if (inet_pton(AF_INET6, v, &addr->sin6.sin6_addr) == 1) {
>
>
Marc
More information about the linux-afs
mailing list