From cddec53a40f6430816d9572fcc20639ac4ae9254 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 5 May 2019 08:30:33 +0100 Subject: [PATCH] pscp: robustness fix in backend cleanup. Coverity points out that in (the misnamed) psftp_main(), I allow for the possibility that 'backend' might be null, up until the final unconditional backend_free(). I haven't actually been able to find a way to make backend() come out as NULL at all in that part of the code: obvious failure modes like trying to scp to a nonexistent host trigger a connection_fatal() which terminates the program without going through that code anyway. But I'm not confident I tried everything, so I can't be sure there _isn't_ a way to get NULL to that location, so let's put in the missing check just in case. --- pscp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pscp.c b/pscp.c index d7e57a5f..8a19c7f4 100644 --- a/pscp.c +++ b/pscp.c @@ -2353,8 +2353,10 @@ int psftp_main(int argc, char *argv[]) random_save_seed(); cmdline_cleanup(); - backend_free(backend); - backend = NULL; + if (backend) { + backend_free(backend); + backend = NULL; + } sk_cleanup(); return (errs == 0 ? 0 : 1); }