This commit fixes two important issues:
1. In parse_name(), ensure qemu_name is never NULL by initializing it to
an empty string when the "guest" option is not provided. This prevents
potential null pointer dereferences.
2. In parse_add_fd(), replace error_abort with proper error handling
using the provided errp parameter. This avoids immediate program
termination on failure and allows for more graceful error reporting.
These changes improve the robustness of the QEMU system emulator by
providing more predictable error handling and preventing potential
crashes.
Signed-off-by: Jun Yu <yujun@kylinos.cn>
---
system/vl.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/system/vl.c b/system/vl.c
index 246623b319..eb07b04044 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -560,6 +560,9 @@ static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
}
qemu_name = qemu_opt_get(opts, "guest");
+ if (!qemu_name) {
+ qemu_name = "";
+ }
proc_name = qemu_opt_get(opts, "process");
if (proc_name) {
@@ -626,7 +629,11 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
/* add the duplicate fd, and optionally the opaque string, to the fd set */
fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque,
- &error_abort);
+ errp);
+ if (!fdinfo) {
+ close(dupfd);
+ return -1;
+ }
g_free(fdinfo);
return 0;
--
2.25.1