[PATCH kvmtool v2 2/7] virtio: Do not modify const strings in virtio_9p_rootdir_parser()
Alexandru Elisei
alexandru.elisei at arm.com
Thu Jun 18 08:49:56 PDT 2026
Even though @arg is of type const char *, virtio_9p_rootdir_parser()
modifies it it if a tag name is specified, leading to the following
compilation error on an x86_64 machine with gcc 15.2.1:
virtio/9p.c:1503:18: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
1503 | tag_name = strstr(arg, ",");
Fix it by copying @arg to a local string, which can then be modified
in-place.
Also use die_perror() if realpath() fails, to provide more information to
the user.
Signed-off-by: Alexandru Elisei <alexandru.elisei at arm.com>
---
virtio/9p.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/virtio/9p.c b/virtio/9p.c
index e6f669c49895..cf3e547d3173 100644
--- a/virtio/9p.c
+++ b/virtio/9p.c
@@ -1491,25 +1491,32 @@ struct virtio_ops p9_dev_virtio_ops = {
int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset)
{
- char *tag_name;
- char tmp[PATH_MAX];
struct kvm *kvm = opt->ptr;
+ char *tag_name, *copy;
+ char path[PATH_MAX];
+ copy = strdup(arg);
+ if (!copy)
+ die_perror("strdup");
/*
* 9p dir can be of the form dirname,tag_name or
* just dirname. In the later case we use the
* default tag name
*/
- tag_name = strstr(arg, ",");
+ tag_name = strstr(copy, ",");
if (tag_name) {
*tag_name = '\0';
tag_name++;
}
- if (realpath(arg, tmp)) {
- if (virtio_9p__register(kvm, tmp, tag_name) < 0)
+ if (realpath(copy, path)) {
+ if (virtio_9p__register(kvm, path, tag_name) < 0)
die("Unable to initialize virtio 9p");
- } else
- die("Failed resolving 9p path");
+ } else {
+ die_perror("Failed resolving 9p path");
+ }
+
+ free(copy);
+
return 0;
}
--
2.54.0
More information about the linux-arm-kernel
mailing list