Skip to content

Commit caed258

Browse files
chriscoolgitster
authored andcommitted
promisor-remote: fix possible issue when no URL is advertised
In the 'KnownUrl' case, in should_accept_remote(), let's check that `remote_url` is not NULL before we use strcmp() to compare it with the local URL. This could avoid crashes if a server starts to not advertise any URL in the future. If `remote_url` is NULL, we should reject the URL. Let's also warn in this case because we warn otherwise when a remote is rejected to try to help diagnose things at the end of the function. And while we are checking that remote_url is not NULL and warning if it is, it makes sense to also help diagnose the case where remote_url is empty. Also while at it, let's spell "URL" with uppercase letters in all the warnings. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b059339 commit caed258

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

promisor-remote.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,15 @@ static int should_accept_remote(enum accept_promisor accept,
409409
if (accept != ACCEPT_KNOWN_URL)
410410
BUG("Unhandled 'enum accept_promisor' value '%d'", accept);
411411

412+
if (!remote_url || !*remote_url) {
413+
warning(_("no or empty URL advertised for remote '%s'"), remote_name);
414+
return 0;
415+
}
416+
412417
if (!strcmp(urls->v[i], remote_url))
413418
return 1;
414419

415-
warning(_("known remote named '%s' but with url '%s' instead of '%s'"),
420+
warning(_("known remote named '%s' but with URL '%s' instead of '%s'"),
416421
remote_name, urls->v[i], remote_url);
417422

418423
return 0;

0 commit comments

Comments
 (0)