]> Kevux Git Server - rit/commitdiff
http: drop const to fix strstr() warning
authorJeff King <peff@peff.net>
Thu, 2 Apr 2026 04:15:14 +0000 (00:15 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2026 05:08:53 +0000 (22:08 -0700)
In redact_sensitive_header(), a C23 implementation of libc will complain
that strstr() assigns the result from "const char *cookie" to "char
*semicolon".

Ultimately the memory is writable. We're fed a strbuf, generate a const
pointer "sensitive_header" within it using skip_iprefix(), and then
assign the result to "cookie".  So we can solve this by dropping the
const from "cookie" and "sensitive_header".

However, this runs afoul of skip_iprefix(), which wants a "const char
**" for its out-parameter. We can solve that by teaching skip_iprefix()
the same "make sure out is at least as const as in" magic that we
recently taught to skip_prefix().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h
http.c

index e9629b2a9dc6d4353e56ee83699852e51ccd53d4..4ddac619921a712297bc5c9bbec8574c89657588 100644 (file)
@@ -902,8 +902,10 @@ static inline size_t xsize_t(off_t len)
  * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
  * locale-specific conversions).
  */
-static inline bool skip_iprefix(const char *str, const char *prefix,
-                              const char **out)
+#define skip_iprefix(str, prefix, out) \
+       skip_iprefix_impl((str), (prefix), CONST_OUTPARAM((str), (out)))
+static inline bool skip_iprefix_impl(const char *str, const char *prefix,
+                                    const char **out)
 {
        do {
                if (!*prefix) {
diff --git a/http.c b/http.c
index 8ea1b9d1f68c16143130aced426df3f224b6c429..8801bd22feed4ad34d2e23461c0306e81cfad86b 100644 (file)
--- a/http.c
+++ b/http.c
@@ -726,7 +726,7 @@ static int has_proxy_cert_password(void)
 static int redact_sensitive_header(struct strbuf *header, size_t offset)
 {
        int ret = 0;
-       const char *sensitive_header;
+       char *sensitive_header;
 
        if (trace_curl_redact &&
            (skip_iprefix(header->buf + offset, "Authorization:", &sensitive_header) ||
@@ -743,7 +743,7 @@ static int redact_sensitive_header(struct strbuf *header, size_t offset)
        } else if (trace_curl_redact &&
                   skip_iprefix(header->buf + offset, "Cookie:", &sensitive_header)) {
                struct strbuf redacted_header = STRBUF_INIT;
-               const char *cookie;
+               char *cookie;
 
                while (isspace(*sensitive_header))
                        sensitive_header++;