[PATCH 11/12] http: drop const to fix strstr() warning
- From
Jeff King <peff@peff.net>
- Date
- Mar 31, 2026, 23:52 UTC
- Message-ID
- <20260331235240.GK2328529@coredump.intra.peff.net>
- In-Reply-To
- <20260331233856.GA2327197@coredump.intra.peff.net>
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> --- git-compat-util.h | 3 +++ http.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h index 58e494e037..f60793fc36 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -914,6 +914,9 @@ static inline bool skip_iprefix(const char *str, const char *prefix, return false; } +#define skip_iprefix(str, prefix, out) \ + skip_iprefix((str), (prefix), CONST_OUTPARAM((str), (out))) + /* * Like skip_prefix_mem, but compare case-insensitively. Note that the * comparison is done via tolower(), so it is strictly ASCII (no multi-byte diff --git a/http.c b/http.c index 8ea1b9d1f6..8801bd22fe 100644 --- 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++;
-- 2.53.0.1136.gd760fbd4a0