From 193255611c0d9907990c74d6fd4d8e7cdf0c1bc1 Mon Sep 17 00:00:00 2001 From: Radu Coriu Date: Sun, 28 Apr 2024 14:04:42 +0300 Subject: [PATCH 1/2] lib/vfscore: Fix warnings in automount.c - remove const from path in vfscore_mount_volume - use the device name for the message in uk_list_for_each_entry_reverse Signed-off-by: Radu Coriu --- lib/vfscore/automount.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/vfscore/automount.c b/lib/vfscore/automount.c index 3f4cc0311c..4d1cfc9bfa 100644 --- a/lib/vfscore/automount.c +++ b/lib/vfscore/automount.c @@ -50,6 +50,9 @@ #include #include #include +#if CONFIG_LIBVFSCORE_AUTOMOUNT || CONFIG_LIBVFSCORE_AUTOUNMOUNT +#include +#endif #include #include #include @@ -625,7 +628,7 @@ static int vfscore_ukopt_mkmp(char *path) */ static inline int vfscore_mount_volume(const struct vfscore_volume *vv) { - const char *path; + char *path; int rc; UK_ASSERT(vv); @@ -863,7 +866,7 @@ static void vfscore_autoumount(const struct uk_term_ctx *tctx __unused) uk_list_for_each_entry_reverse(mp, &mount_list, mnt_list) { uk_pr_info("Unmounting %s (%s)...\n", mp->m_path, - mp->m_dev ? mp->m_dev : "none"); + mp->m_dev ? mp->m_dev->name : "none"); /* For now, flags = 0 is enough. */ rc = VFS_UNMOUNT(mp, 0); if (unlikely(rc)) From 409f778b999b25254508396c475762653d49efa2 Mon Sep 17 00:00:00 2001 From: Radu Coriu Date: Wed, 5 Jun 2024 17:18:09 +0300 Subject: [PATCH 2/2] lib/vfscore: Fix warnings in automount.c - make path const again in vfscore_mount_volume - make path param const in vfscore_ukopt_mkmp and use strdup/free to avoid writing to readonly input string Signed-off-by: Radu Coriu --- lib/vfscore/automount.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/vfscore/automount.c b/lib/vfscore/automount.c index 4d1cfc9bfa..e0a90c94da 100644 --- a/lib/vfscore/automount.c +++ b/lib/vfscore/automount.c @@ -564,9 +564,10 @@ 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) { char *pos, *prev_pos; + char *tmp_path; int rc; UK_ASSERT(path); @@ -578,7 +579,14 @@ static int vfscore_ukopt_mkmp(char *path) } uk_pr_debug(" mkmp: Ensure mount path \"%s\" exists\n", path); - pos = path; + tmp_path = strdup(path); + if (!tmp_path) + { + uk_pr_err("strdup failed with errno=%d\n", errno); + return -errno; + } + + pos = tmp_path; do { prev_pos = pos; pos = strchr(pos + 1, '/'); @@ -602,23 +610,24 @@ static int vfscore_ukopt_mkmp(char *path) (prev_pos[2] == '/' || prev_pos[2] == '\0') ))) { uk_pr_err("'.' or '..' are not supported in mount paths.\n"); + free(tmp_path); return -EINVAL; } /* mkdir() with S_IRWXU */ rc = mkdir(path, 0700); if (rc && errno != EEXIST) + { + free(tmp_path); return -errno; - - /* Restore current '/' */ - if (pos) - *pos = '/'; + } /* Handle paths with multiple `/` */ while (pos && pos[1] == '/') pos++; } while (pos); + free(tmp_path); return 0; } @@ -628,7 +637,7 @@ static int vfscore_ukopt_mkmp(char *path) */ static inline int vfscore_mount_volume(const struct vfscore_volume *vv) { - char *path; + const char *path; int rc; UK_ASSERT(vv);