[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 07/10] qmp: 'add_client' actually expects sockets
From: |
marcandre . lureau |
Subject: |
[PATCH 07/10] qmp: 'add_client' actually expects sockets |
Date: |
Tue, 3 Jan 2023 15:08:11 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Whether it is SPICE, VNC, D-Bus, or the socket chardev, they all
actually expect a socket kind or will fail in different ways at runtime.
Throw an error early if the given 'add_client' fd is not a socket, and
close it to avoid leaks.
This allows to replace the close() call with a more correct & portable
closesocket() version.
(this will allow importing sockets on Windows with a specialized command
in the following patch, while keeping the remaining monitor associated
sockets/add_client code & usage untouched)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
monitor/qmp-cmds.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 2932b3f3a5..c491eb262b 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -20,6 +20,7 @@
#include "sysemu/sysemu.h"
#include "qemu/config-file.h"
#include "qemu/uuid.h"
+#include "qemu/sockets.h"
#include "chardev/char.h"
#include "ui/qemu-spice.h"
#include "ui/console.h"
@@ -248,16 +249,22 @@ void qmp_add_client(const char *protocol, const char
*fdname,
return;
}
+ if (!fd_is_socket(fd)) {
+ error_setg(errp, "add_client expects a socket");
+ close(fd);
+ return;
+ }
+
if (strcmp(protocol, "spice") == 0) {
if (!qemu_using_spice(errp)) {
- close(fd);
+ closesocket(fd);
return;
}
skipauth = has_skipauth ? skipauth : false;
tls = has_tls ? tls : false;
if (qemu_spice.display_add_client(fd, skipauth, tls) < 0) {
error_setg(errp, "spice failed to add client");
- close(fd);
+ closesocket(fd);
}
return;
#ifdef CONFIG_VNC
@@ -269,11 +276,11 @@ void qmp_add_client(const char *protocol, const char
*fdname,
#ifdef CONFIG_DBUS_DISPLAY
} else if (strcmp(protocol, "@dbus-display") == 0) {
if (!qemu_using_dbus_display(errp)) {
- close(fd);
+ closesocket(fd);
return;
}
if (!qemu_dbus_display.add_client(fd, errp)) {
- close(fd);
+ closesocket(fd);
return;
}
return;
@@ -281,14 +288,14 @@ void qmp_add_client(const char *protocol, const char
*fdname,
} else if ((s = qemu_chr_find(protocol)) != NULL) {
if (qemu_chr_add_client(s, fd) < 0) {
error_setg(errp, "failed to add client");
- close(fd);
+ closesocket(fd);
return;
}
return;
}
error_setg(errp, "protocol '%s' is invalid", protocol);
- close(fd);
+ closesocket(fd);
}
--
2.39.0
- Re: [PATCH 02/10] tests: fix path separator, use g_build_filename(), (continued)
- [PATCH 03/10] tests: fix test-io-channel-command on win32, marcandre . lureau, 2023/01/03
- [PATCH 01/10] ccid-card-emulated: fix cast warning/error, marcandre . lureau, 2023/01/03
- [PATCH 04/10] tests/docker: fix a win32 error due to portability, marcandre . lureau, 2023/01/03
- [PATCH 05/10] tests/readconfig: spice doesn't support unix socket on windows yet, marcandre . lureau, 2023/01/03
- [PATCH 06/10] osdep: implement qemu_socketpair() for win32, marcandre . lureau, 2023/01/03
- [PATCH 07/10] qmp: 'add_client' actually expects sockets,
marcandre . lureau <=
- [PATCH 08/10] qmp: add 'get-win32-socket', marcandre . lureau, 2023/01/03
- [PATCH 09/10] libqtest: make qtest_qmp_add_client work on win32, marcandre . lureau, 2023/01/03
- [PATCH 10/10] qtest: enable vnc-display test on win32, marcandre . lureau, 2023/01/03
- Re: [PATCH 00/10] Various win32 fixes & new 'get-win32-socket' QMP command, Philippe Mathieu-Daudé, 2023/01/03