]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Fix write const path in automount
authorAndrei Tatar <andrei@unikraft.io>
Tue, 29 Apr 2025 13:54:03 +0000 (15:54 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Tue, 29 Apr 2025 14:15:52 +0000 (14:15 +0000)
Previously vfscore_mount_volume would pass a const path to
vfscore_ukopt_mkmp, which expects a mutable path, and indeed does modify
it in-place during execution. This is wrong and rightfully triggers a
compiler warning.
This change fixes this by having mkmp allocate a temporary writable path.

Checkpatch-Ignore: STRCPY
Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1636

lib/vfscore/automount.c

index 4ab4f0abf8c9ac910e3378a881ad104fd5933ec4..8e78c1f2fbb201ba3916818bdaf5b86d8acc654d 100644 (file)
@@ -568,18 +568,19 @@ static int vfscore_extract_volume(const struct vfscore_volume *vv)
 #endif /* CONFIG_LIBUKCPIO */
 
 /* Handle `mkmp` Unikraft Mount Option */
-static int vfscore_ukopt_mkmp(char *path)
+static int vfscore_ukopt_mkmp(const char *path_arg)
 {
+       char path[strlen(path_arg) + 1];
        char *pos, *prev_pos;
        int rc;
 
-       UK_ASSERT(path);
-       UK_ASSERT(path[0] == '/');
+       UK_ASSERT(path_arg[0] == '/');
 
-       if (path[1] == '\0') {
+       if (path_arg[1] == '\0') {
                uk_pr_debug(" mkmp: Called on '/', nothing to pre-create\n");
                return 0;
        }
+       strcpy(path, path_arg);
 
        uk_pr_debug(" mkmp: Ensure mount path \"%s\" exists\n", path);
        pos = path;