curl: anonymize URLs in error messages and warnings
Just like 47abd85ba0 (fetch: Strip usernames from url's before storing them, 2009-04-17) and later 882d49ca5c (push: anonymize URL in status output, 2016-07-13), this change anonymizes URLs (read: strips them of user names and especially passwords) in user-facing error messages and warnings. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Mar 4, 2019 at 07:33 UTC
c1284b21f2436de24c9559fcc5f4badb04f47773
1 file changed
+13
-6
remote-curl.c
+13
-6
@@ -16,6 +16,7 @@
16
#include "send-pack.h"
17
#include "protocol.h"
18
#include "quote.h"
19
+#include "transport.h"
20
21
static struct remote *remote;
22
/* always ends with a trailing slash */
@@ -250,7 +251,7 @@ static struct ref *parse_info_refs(struct discovery *heads)
251
if (data[i] == '\n') {
252
if (mid - start != 40)
253
die("%sinfo/refs not valid: is this a git repository?",
253
- url.buf);
254
+ transport_anonymize_url(url.buf));
255
data[i] = 0;
256
ref_name = mid + 1;
257
ref = alloc_ref(ref_name);
@@ -388,17 +389,23 @@ static struct discovery *discover_refs(const char *service, int for_push)
389
break;
390
case HTTP_MISSING_TARGET:
391
show_http_message(&type, &charset, &buffer);
391
- die("repository '%s' not found", url.buf);
392
+ die("repository '%s' not found",
393
+ transport_anonymize_url(url.buf));
394
case HTTP_NOAUTH:
395
show_http_message(&type, &charset, &buffer);
394
- die("Authentication failed for '%s'", url.buf);
396
+ die("Authentication failed for '%s'",
397
+ transport_anonymize_url(url.buf));
398
default:
399
show_http_message(&type, &charset, &buffer);
397
- die("unable to access '%s': %s", url.buf, curl_errorstr);
400
+ die("unable to access '%s': %s",
401
+ transport_anonymize_url(url.buf), curl_errorstr);
402
}
403
400
- if (options.verbosity && !starts_with(refs_url.buf, url.buf))
401
- warning(_("redirecting to %s"), url.buf);
404
+ if (options.verbosity && !starts_with(refs_url.buf, url.buf)) {
405
+ char *u = transport_anonymize_url(url.buf);
406
+ warning(_("redirecting to %s"), u);
407
+ free(u);
408
+ }
409
410
last= xcalloc(1, sizeof(*last_discovery));
411
last->service = xstrdup(service);