Re: [PATCH 1/3] transport_anonymize_url(): support retaining username
- From
René Scharfe <l.s.r@web.de>
- Date
- May 20, 2019, 16:14 UTC
- Message-ID
- <29276251-0dd4-d22c-4479-7de52efc35b2@web.de>
- In-Reply-To
- <20190519051031.GA19434@sigill.intra.peff.net>
Am 19.05.19 um 07:10 schrieb Jeff King:
Show 15 quoted lines
> diff --git a/transport.c b/transport.c
> index f1fcd2c4b0..ba61e57295 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -1373,7 +1372,15 @@ char *transport_anonymize_url(const char *url)
> cp = strchr(scheme_prefix + 3, '/');
> if (cp && cp < anon_part)
> goto literal_copy;
> - prefix_len = scheme_prefix - url + 3;
> +
> + if (strip_user)
> + prefix_len = scheme_prefix - url + 3;
> + else {
> + cp = strchr(scheme_prefix + 3, ':');
> + if (cp && cp > anon_part)Don't you mean this?
if (!cp || cp > anon_part)
Or the search could stop at anon_part in the first place:
assert(scheme_prefix + 3 < anon_part); cp = memchr(schema_prefix + 3, ':', anon_part - schema_prefix - 3); if (!cp)
That whole thing looks fragile. I wonder if using the official regex (https://tools.ietf.org/html/rfc3986#appendix-B) would make it easier and more robust.
> + goto literal_copy; /* username only */ > + prefix_len = cp - url;
Anyway, you don't want cp == NULL here.
> + }
> }
> return xstrfmt("%.*s%.*s", (int)prefix_len, url,
> (int)anon_len, anon_part);