diff mbox series

BUG: util: Append missing slash to temporary mount dir

Message ID 20241219100411.356551-2-Michael.Glembotzki@iris-sensing.com
State Accepted
Headers show
Series BUG: util: Append missing slash to temporary mount dir | expand

Commit Message

Michael Glembotzki Dec. 19, 2024, 10:04 a.m. UTC
The raw_handler requires a slash between the mountpoint and the file path.
Otherwise, no correct mount is performed, and the file is saved to the wrong
location.

[TRACE] : SWUPDATE running :  [install_raw_file] : Installing file fitimage.itb.signed on /tmp/datadst/UEE6x2fitImage.signed

Fixes: 5d57a9c05ec2 (util: introduce generic mount helpers)
Fixes: aff67cdb2c62 (Make use of introduced swupdate_temporary_(u)mount)
Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>

---

The bug is pretty bad because, for example, it caused parts of the update
(e.g. for us the kernel fitimage) to not be installed. I could imagine that
some systems would not boot as expected.

Only the raw_handler has been tested. Other handlers, such as rdiff, btrfs,
archive, delta, could also be affected and should be explicitly tested.

 core/util.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index 32104279..da3e815b 100644
--- a/core/util.c
+++ b/core/util.c
@@ -873,6 +873,7 @@  char *swupdate_temporary_mount(tmp_mountpoint_t type, const char *device, const
 	char *mountpoint;
 	const char *dir;
 	int ret = 0;
+	unsigned int len;
 
 	if (type != MNT_SCRIPTS && type != MNT_DATA && type != MNT_BOOT_SCRIPTS)
 		return NULL;
@@ -883,10 +884,13 @@  char *swupdate_temporary_mount(tmp_mountpoint_t type, const char *device, const
 	}
 
 	dir = mount_points[type];
-	if (asprintf(&mountpoint, "%s%sXXXXXX", get_tmpdir(), dir) == -1) {
+	len = strlen(get_tmpdir()) + strlen(dir) + 8; /* 6 times X, / and \0 */
+	mountpoint = (char*) calloc(len, sizeof(char));
+	if (!mountpoint) {
 		ERROR("Unable to allocate memory");
 		return NULL;
 	}
+	snprintf(mountpoint, len, "%s%sXXXXXX", get_tmpdir(), dir);
 
 	if (!mkdtemp(mountpoint)) {
 		TRACE("Unable to create a unique temporary directory %s: %s",
@@ -904,6 +908,8 @@  char *swupdate_temporary_mount(tmp_mountpoint_t type, const char *device, const
 		return NULL;
 	}
 
+	mountpoint[len-2] = '/';
+
 	return mountpoint;
 }