From: tangxiaofeng <tangxiaofeng@kylinos.cn>
Date: Mon, 19 Oct 2026 20:57:47 +0000
Subject: [PATCH] Fix FTBFS with the C23 qualifier-generic strchr()

ngx_strchr() casts its argument to "const char *", so with a C23 conforming
glibc (>= 2.43) strchr() is a qualifier-generic macro (ISO C23) that returns a
"const char *" when the argument is const-qualified.  The pointer returned by
ngx_strchr() is assigned to a "char *" pointing into the writable buffer
allocated with ngx_palloc(), and nginx compiles modules with -Werror, so the
assignment is rejected with -Werror=discarded-qualifiers.  Convert the pointer
back with the discard_const() macro already provided by this module; the
generated code and the module behaviour are unchanged on every toolchain and
architecture.

---
Description: Fix FTBFS with the C23 qualifier-generic strchr()
Author: tangxiaofeng <tangxiaofeng@kylinos.cn>
Forwarded: no
Last-Update: 2026-10-19

--- libnginx-mod-http-auth-spnego-1.1.3.orig/ngx_http_auth_spnego_module.c
+++ libnginx-mod-http-auth-spnego-1.1.3/ngx_http_auth_spnego_module.c
@@ -767,7 +767,12 @@ static char *ngx_http_auth_spnego_replac
     ngx_memcpy(result, str, ngx_strlen(str) + 1);
 
     char *index = NULL;
-    while ((index = ngx_strchr(result, find)) != NULL) {
+    /* ngx_strchr() casts its argument to "const char *"; with the C23
+     * qualifier-generic strchr() the pointer it returns is therefore const and
+     * must be converted back before writing to the writable buffer allocated
+     * above.
+     */
+    while ((index = discard_const(ngx_strchr(result, find))) != NULL) {
         *index = replace;
     }
     return result;
