Skip to content

Commit 8a0566b

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 c395126 commit 8a0566b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

git-compat-util.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,10 @@ static inline size_t xsize_t(off_t len)
902902
* is done via tolower(), so it is strictly ASCII (no multi-byte characters or
903903
* locale-specific conversions).
904904
*/
905-
static inline bool skip_iprefix(const char *str, const char *prefix,
906-
const char **out)
905+
#define skip_iprefix(str, prefix, out) \
906+
skip_iprefix_impl((str), (prefix), CONST_OUTPARAM((str), (out)))
907+
static inline bool skip_iprefix_impl(const char *str, const char *prefix,
908+
const char **out)
907909
{
908910
do {
909911
if (!*prefix) {

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)