git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Jeff KingNext: Jeff King
Message 26 of 50 in “fixing the remainder of the C23 strchr warnings”
  1. 0/12 fixing the remainder of the C23 strchr warningsJeff King, Mar 31, 2026
  2. 01/12 convert: add const to fix strchr() warningsJeff King, Mar 31, 2026
  3. 02/12 http: add const to fix strchr() warningsJeff King, Mar 31, 2026
  4. 03/12 transport-helper: drop const to fix strchr() warningsJeff King, Mar 31, 2026
  5. Patrick SteinhardtApr 1, 2026
  6. 04/12 pager: explicitly cast away strchr() constnessJeff King, Mar 31, 2026
  7. Junio C HamanoApr 1, 2026
  8. Jeff KingApr 2, 2026
  9. 05/12 run-command: explicitly cast away constness when assigning to voidJeff King, Mar 31, 2026
  10. 06/12 find_last_dir_sep(): convert inline function to macroJeff King, Mar 31, 2026
  11. 07/12 pseudo-merge: fix disk reads from find_pseudo_merge()Jeff King, Mar 31, 2026
  12. Jeff KingMar 31, 2026
  13. Junio C HamanoApr 1, 2026
  14. Taylor BlauApr 2, 2026
  15. 08/12 skip_prefix(): check const match between in and out paramsJeff King, Mar 31, 2026
  16. Phillip WoodApr 1, 2026
  17. Phillip WoodApr 1, 2026
  18. Jeff KingApr 1, 2026
  19. Junio C HamanoApr 1, 2026
  20. Phillip WoodApr 2, 2026
  21. Patrick SteinhardtApr 1, 2026
  22. 09/12 pkt-line: make packet_reader.line non-constJeff King, Mar 31, 2026
  23. Junio C HamanoApr 1, 2026
  24. Jeff KingApr 2, 2026
  25. 10/12 range-diff: drop const to fix strstr() warningsJeff King, Mar 31, 2026
  26. 11/12 http: drop const to fix strstr() warningJeff King, Mar 31, 2026
  27. 12/12 refs/files-backend: drop const to fix strchr() warningJeff King, Mar 31, 2026
  28. Patrick SteinhardtApr 1, 2026
  29. Junio C HamanoApr 1, 2026
  30. Jeff KingApr 2, 2026
  31. 0/12 fixing the remainder of the C23 strchr warningsJeff King, Apr 2, 2026
  32. 01/12 convert: add const to fix strchr() warningsJeff King, Apr 2, 2026
  33. 02/12 http: add const to fix strchr() warningsJeff King, Apr 2, 2026
  34. 03/12 transport-helper: drop const to fix strchr() warningsJeff King, Apr 2, 2026
  35. 04/12 pager: explicitly cast away strchr() constnessJeff King, Apr 2, 2026
  36. 05/12 run-command: explicitly cast away constness when assigning to voidJeff King, Apr 2, 2026
  37. 06/12 find_last_dir_sep(): convert inline function to macroJeff King, Apr 2, 2026
  38. 07/12 pseudo-merge: fix disk reads from find_pseudo_merge()Jeff King, Apr 2, 2026
  39. 08/12 skip_prefix(): check const match between in and out paramsJeff King, Apr 2, 2026
  40. Junio C HamanoApr 2, 2026
  41. Jeff KingApr 2, 2026
  42. Junio C HamanoApr 2, 2026
  43. Junio C HamanoApr 2, 2026
  44. Toon ClaesApr 3, 2026
  45. 13/12 git-compat-util: fix CONST_OUTPARAM typo and indentationJeff King, Apr 4, 2026
  46. 09/12 pkt-line: make packet_reader.line non-constJeff King, Apr 2, 2026
  47. 10/12 range-diff: drop const to fix strstr() warningsJeff King, Apr 2, 2026
  48. 11/12 http: drop const to fix strstr() warningJeff King, Apr 2, 2026
  49. 12/12 refs/files-backend: drop const to fix strchr() warningJeff King, Apr 2, 2026
  50. Toon ClaesApr 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.