From 8ee1009874d11a61ccd4b89322432c3633b4cc1f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 6 Nov 2018 13:10:30 +0000 Subject: transport: see if cert/cred callbacks exist before calling them Custom transports may want to ask libgit2 to invoke a configured credential or certificate callback; however they likely do not know if a callback was actually configured. Return a sentinal value (GIT_PASSTHROUGH) if there is no callback configured instead of crashing. --- src/transports/smart.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/transports') diff --git a/src/transports/smart.c b/src/transports/smart.c index e972d30ba..9fcbdcf21 100644 --- a/src/transports/smart.c +++ b/src/transports/smart.c @@ -481,6 +481,11 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce { transport_smart *t = (transport_smart *)transport; + assert(transport && cert && hostname); + + if (!t->certificate_check_cb) + return GIT_PASSTHROUGH; + return t->certificate_check_cb(cert, valid, hostname, t->message_cb_payload); } @@ -488,6 +493,11 @@ int git_transport_smart_credentials(git_cred **out, git_transport *transport, co { transport_smart *t = (transport_smart *)transport; + assert(out && transport); + + if (!t->cred_acquire_cb) + return GIT_PASSTHROUGH; + return t->cred_acquire_cb(out, t->url, user, methods, t->cred_acquire_payload); } -- cgit v1.2.1