Skip to content

Commit b850c12

Browse files
peffgitster
authored andcommitted
http: drop const to fix strstr() warning
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>
1 parent 81df4e0 commit b850c12

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

git-compat-util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@ static inline bool skip_iprefix(const char *str, const char *prefix,
914914
return false;
915915
}
916916

917+
#define skip_iprefix(str, prefix, out) \
918+
skip_iprefix((str), (prefix), CONST_OUTPARAM((str), (out)))
919+
917920
/*
918921
* Like skip_prefix_mem, but compare case-insensitively. Note that the
919922
* comparison is done via tolower(), so it is strictly ASCII (no multi-byte

http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ static int has_proxy_cert_password(void)
726726
static int redact_sensitive_header(struct strbuf *header, size_t offset)
727727
{
728728
int ret = 0;
729-
const char *sensitive_header;
729+
char *sensitive_header;
730730

731731
if (trace_curl_redact &&
732732
(skip_iprefix(header->buf + offset, "Authorization:", &sensitive_header) ||
@@ -743,7 +743,7 @@ static int redact_sensitive_header(struct strbuf *header, size_t offset)
743743
} else if (trace_curl_redact &&
744744
skip_iprefix(header->buf + offset, "Cookie:", &sensitive_header)) {
745745
struct strbuf redacted_header = STRBUF_INIT;
746-
const char *cookie;
746+
char *cookie;
747747

748748
while (isspace(*sensitive_header))
749749
sensitive_header++;

0 commit comments

Comments
 (0)