summaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorKim Altintop <kim.altintop@gmail.com>2020-08-31 21:54:17 +0200
committerKim Altintop <kim.altintop@gmail.com>2020-08-31 21:54:17 +0200
commit7e1f0b222d581c5484622166b6f8041ee004cb17 (patch)
tree4d58ccb223fa7258e8c91576d06a0140223ec062 /src/net.c
parentc71321a099373753c22055921c8f538afed5ebb6 (diff)
downloadlibgit2-7e1f0b222d581c5484622166b6f8041ee004cb17.tar.gz
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).
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/net.c b/src/net.c
index d42fce52d..dbde626b5 100644
--- a/src/net.c
+++ b/src/net.c
@@ -336,7 +336,12 @@ bool git_net_url_valid(git_net_url *url)
int git_net_url_is_default_port(git_net_url *url)
{
- return (strcmp(url->port, default_port_for_scheme(url->scheme)) == 0);
+ const char *default_port;
+
+ if ((default_port = default_port_for_scheme(url->scheme)) != NULL)
+ return (strcmp(url->port, default_port) == 0);
+ else
+ return false;
}
void git_net_url_swap(git_net_url *a, git_net_url *b)