Commit dbaf84e148 for qemu.org
commit dbaf84e148b0c8b66dcb47788a6bb13806e401e4
Author: Christian Schoenebeck <qemu_oss@crudebyte.com>
Date: Mon May 18 19:35:53 2026 +0200
hw/9pfs: change V9fsPath.size to size_t and v9fs_path_sprintf() return type
- Change V9fsPath.size from uint16_t to size_t to support paths larger
than 65536 bytes.
- Change v9fs_path_sprintf() return type from void to int to allow error
reporting.
Link: https://lore.kernel.org/qemu-devel/2d2348d94ff43fbe4cc0aea24fb312c5c15ee809.1779126034.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index b85c9934de..e8d0661c4b 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -112,7 +112,7 @@ struct FsContext {
};
struct V9fsPath {
- uint16_t size;
+ size_t size;
char *data;
};
P9ARRAY_DECLARE_TYPE(V9fsPath);
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index e590c414ab..88894ec9d2 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -203,16 +203,24 @@ void v9fs_path_free(V9fsPath *path)
}
-void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...)
+int v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...)
{
va_list ap;
+ int ret;
v9fs_path_free(path);
va_start(ap, fmt);
- /* Bump the size for including terminating NULL */
- path->size = g_vasprintf(&path->data, fmt, ap) + 1;
+ ret = g_vasprintf(&path->data, fmt, ap);
va_end(ap);
+ if (ret < 0) {
+ error_report_once("9pfs: unusual path formatting failure; "
+ "invalidating associated FID");
+ return -1;
+ }
+ /* Bump the size for including terminating NULL */
+ path->size = ret + 1;
+ return 0;
}
void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src)
diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h
index 65cc45e344..b2df659b0e 100644
--- a/hw/9pfs/9p.h
+++ b/hw/9pfs/9p.h
@@ -456,8 +456,8 @@ static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu)
void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu);
void v9fs_path_init(V9fsPath *path);
void v9fs_path_free(V9fsPath *path);
-void G_GNUC_PRINTF(2, 3) v9fs_path_sprintf(V9fsPath *path, const char *fmt,
- ...);
+int G_GNUC_PRINTF(2, 3) v9fs_path_sprintf(V9fsPath *path, const char *fmt,
+ ...);
void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src);
size_t v9fs_readdir_response_size(V9fsString *name);
int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,