Re: [PATCH] http: handle both "h2" and "h2h3" in curl info lines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jun 17, 2023 at 01:15:59AM -0400, Jeff King wrote:

> diff --git a/http.c b/http.c
> index bb58bb3e6a..b71bb1e3ad 100644
> --- a/http.c
> +++ b/http.c
> @@ -746,7 +746,8 @@ static void redact_sensitive_info_header(struct strbuf *header)
>  	 *   h2h3 [<header-name>: <header-val>]
>  	 */
>  	if (trace_curl_redact &&
> -	    skip_iprefix(header->buf, "h2h3 [", &sensitive_header)) {
> +	    (skip_iprefix(header->buf, "h2h3 [", &sensitive_header) ||
> +	     skip_iprefix(header->buf, "h2 [", &sensitive_header))) {
>  		if (redact_sensitive_header(header, sensitive_header - header->buf)) {
>  			/* redaction ate our closing bracket */
>  			strbuf_addch(header, ']');

I of course found it unsatisfying that we are not taking advantage of
the fact that "h2" is a subset of "h2h3". But optionally skipping past
h3 in the middle of an &&-chain is awkward (you have to write
"skip_prefix() || 1"). We could rewrite it with early returns, as below,
but I think the result is probably less readable.

diff --git a/http.c b/http.c
index b71bb1e3ad..1abfaad4c1 100644
--- a/http.c
+++ b/http.c
@@ -741,17 +741,23 @@ static void redact_sensitive_info_header(struct strbuf *header)
 {
 	const char *sensitive_header;
 
+	if (!trace_curl_redact)
+		return;
+
 	/*
-	 * curl's h2h3 prints headers in info, e.g.:
+	 * curl's http/2 prints headers in info with either an "h2" or an
+	 * "h2h3" prefix, e.g.:
 	 *   h2h3 [<header-name>: <header-val>]
 	 */
-	if (trace_curl_redact &&
-	    (skip_iprefix(header->buf, "h2h3 [", &sensitive_header) ||
-	     skip_iprefix(header->buf, "h2 [", &sensitive_header))) {
-		if (redact_sensitive_header(header, sensitive_header - header->buf)) {
-			/* redaction ate our closing bracket */
-			strbuf_addch(header, ']');
-		}
+	if (!skip_iprefix(header->buf, "h2", &sensitive_header))
+		return;
+	skip_iprefix(sensitive_header, "h3", &sensitive_header);
+	if (!skip_prefix(sensitive_header, " [", &sensitive_header))
+		return;
+
+	if (redact_sensitive_header(header, sensitive_header - header->buf)) {
+		/* redaction ate our closing bracket */
+		strbuf_addch(header, ']');
 	}
 }
 



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux