diff mbox series

BUG: copyhandler: wrong path passed to chained handler

Message ID 20250703072134.25167-1-stefano.babic@swupdate.org
State Accepted
Headers show
Series BUG: copyhandler: wrong path passed to chained handler | expand

Commit Message

Stefano Babic July 3, 2025, 7:21 a.m. UTC
The copyhandler creates the destination but doing this, the destination
path is split into two strings and just the basename is passed to the
chained handler. So the copyhandler does not work when
"create-destination" is set.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
Reported-by: Joshua Bernimoulin <jbernimoulin@gmail.com>
---
 handlers/copy_handler.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
index ae7315ca..2408581e 100644
--- a/handlers/copy_handler.c
+++ b/handlers/copy_handler.c
@@ -319,7 +319,13 @@  static int copy_image_file(struct img_type *img, void *data)
 			ERROR("Destination must be created, but no path set");
 			return -EINVAL;
 		}
-		ret = mkpath(recursive ? base_img->path : dirname(base_img->path), 0755);
+		char *tmppath = strdup(img->path);
+		if (!tmppath) {
+			ERROR("OOM creating local image path");
+			return -ENOMEM;
+		}
+		ret = mkpath(recursive ? tmppath : dirname(tmppath), 0755);
+		free(tmppath);
 		if (ret < 0) {
 			ERROR("I cannot create path %s: %s",
 				recursive ? base_img->path : dirname(base_img->path),