Skip to content

Commit 7e1f0b2

Browse files
committed
Return false instead of segfaulting when checking for default port
`default_port_for_scheme` returns NULL if the scheme is not one of the builtin ones. This may cause a segmentation fault if a custom transport URL happens to contain a port number, and this code path is triggered (e.g. by setting git_fetch_options->update_fetchhead to 1).
1 parent c71321a commit 7e1f0b2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/net.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,12 @@ bool git_net_url_valid(git_net_url *url)
336336

337337
int git_net_url_is_default_port(git_net_url *url)
338338
{
339-
return (strcmp(url->port, default_port_for_scheme(url->scheme)) == 0);
339+
const char *default_port;
340+
341+
if ((default_port = default_port_for_scheme(url->scheme)) != NULL)
342+
return (strcmp(url->port, default_port) == 0);
343+
else
344+
return false;
340345
}
341346

342347
void git_net_url_swap(git_net_url *a, git_net_url *b)

0 commit comments

Comments
 (0)