diff mbox series

Re: [PATCH] BUG: util: Append missing slash to temporary mount dir

Message ID ad2465fa-97cd-4896-994f-deacfb5c27ecn@googlegroups.com
State Changes Requested
Headers show
Series Re: [PATCH] BUG: util: Append missing slash to temporary mount dir | expand

Commit Message

Einar Jon Gunnarsson Dec. 19, 2024, 10:46 a.m. UTC
Hello Michael 

Is there any reason why this isn't just

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; 
}
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index 32104279..c210a3e1 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,12 @@  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 = asprintf(&mountpoint, "%s%sXXXXXX/", get_tmpdir(), dir);
+       if (len == -1) {
                ERROR("Unable to allocate memory");
                return NULL;
        }
+       mountpoint[len-1] = '\0'; /* last six characters of template must 
be XXXXXX */
 
        if (!mkdtemp(mountpoint)) {
                TRACE("Unable to create a unique temporary directory %s: 
%s",
@@ -904,6 +907,7 @@  char *swupdate_temporary_mount(tmp_mountpoint_t type, 
const char *device, const
                return NULL;
        }
 
+       mountpoint[len-1] = '/';  /* restore the trailing slash */
        return mountpoint;
 }
 
Best regards
Einar Jon

On Thursday, 19 December 2024 at 11:08:09 UTC+1 Michael Glembotzki wrote:

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.G...@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 --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)