From c3d396b5feb1a77a3b9d26bf948d83518f8e7e4e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 1 Mar 2026 04:58:28 +0100 Subject: [PATCH] copy: fix null dst dereference and uninit uri_i in curl() Found by Coverity Scan Signed-off-by: Joachim Wiberg --- src/bin/copy.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bin/copy.c b/src/bin/copy.c index 763a6aba..80334450 100644 --- a/src/bin/copy.c +++ b/src/bin/copy.c @@ -466,7 +466,7 @@ static int curl(char *op, const char *path, const char *uri) { char *argv[10] = { "curl", "-L", NULL }; int err = 1, i = 2; - int path_i, uri_i, user_i = 0; + int path_i, uri_i = 0, user_i = 0; argv[i++] = op; @@ -492,7 +492,8 @@ static int curl(char *op, const char *path, const char *uri) out: free(argv[path_i]); - free(argv[uri_i]); + if (uri_i) + free(argv[uri_i]); if (user_i) free(argv[user_i]); return err; @@ -752,7 +753,7 @@ static int copy(const char *src, const char *dst) * meaningful name instead: the datastore's on-disk filename, or the * source file's own basename. */ - if (is_ssh_uri(dst) && dst[strlen(dst) - 1] == '/') { + if (dst && is_ssh_uri(dst) && dst[strlen(dst) - 1] == '/') { const char *bn, *slash; if (srcds && srcds->path) {