[PATCH] Fix modification of read-only string
David Howells
dhowells at redhat.com
Tue Feb 3 01:03:43 PST 2026
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;
v++;
p = strchr(v, ']');
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) {
More information about the linux-afs
mailing list