[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 20/25] qmp: 'add_client' actually expects sockets
From: |
marcandre . lureau |
Subject: |
[PULL v2 20/25] qmp: 'add_client' actually expects sockets |
Date: |
Mon, 13 Mar 2023 15:46:43 +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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20230306122751.2355515-6-marcandre.lureau@redhat.com>
---
qapi/misc.json | 3 +++
monitor/qmp-cmds.c | 7 +++++++
2 files changed, 10 insertions(+)
diff --git a/qapi/misc.json b/qapi/misc.json
index 27ef5a2b20..f0217cfba0 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -14,6 +14,9 @@
# Allow client connections for VNC, Spice and socket based
# character devices to be passed in to QEMU via SCM_RIGHTS.
#
+# If the FD associated with @fdname is not a socket, the command will fail and
+# the FD will be closed.
+#
# @protocol: protocol name. Valid names are "vnc", "spice", "@dbus-display" or
# the name of a character device (eg. from -chardev id=XXXX)
#
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 859012aef4..b0f948d337 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -14,6 +14,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/sockets.h"
#include "monitor-internal.h"
#include "monitor/qdev.h"
#include "monitor/qmp-helpers.h"
@@ -139,6 +140,12 @@ void qmp_add_client(const char *protocol, const char
*fdname,
return;
}
+ if (!fd_is_socket(fd)) {
+ error_setg(errp, "parameter @fdname must name a socket");
+ close(fd);
+ return;
+ }
+
for (i = 0; i < ARRAY_SIZE(protocol_table); i++) {
if (!strcmp(protocol, protocol_table[i].name)) {
if (!protocol_table[i].add_client(fd, has_skipauth, skipauth,
--
2.39.2
- [PULL v2 11/25] slirp: unregister the win32 SOCKET, (continued)
- [PULL v2 11/25] slirp: unregister the win32 SOCKET, marcandre . lureau, 2023/03/13
- [PULL v2 12/25] slirp: open-code qemu_socket_(un)select(), marcandre . lureau, 2023/03/13
- [PULL v2 14/25] os-posix: remove useless ioctlsocket() define, marcandre . lureau, 2023/03/13
- [PULL v2 15/25] win32: replace closesocket() with close() wrapper, marcandre . lureau, 2023/03/13
- [PULL v2 13/25] win32: avoid mixing SOCKET and file descriptor space, marcandre . lureau, 2023/03/13
- [PULL v2 17/25] char: do not double-close fd when failing to add client, marcandre . lureau, 2023/03/13
- [PULL v2 19/25] osdep: implement qemu_socketpair() for win32, marcandre . lureau, 2023/03/13
- [PULL v2 16/25] tests: fix path separator, use g_build_filename(), marcandre . lureau, 2023/03/13
- [PULL v2 21/25] monitor: release the lock before calling close(), marcandre . lureau, 2023/03/13
- [PULL v2 22/25] qmp: add 'get-win32-socket', marcandre . lureau, 2023/03/13
- [PULL v2 20/25] qmp: 'add_client' actually expects sockets,
marcandre . lureau <=
- [PULL v2 18/25] tests/docker: fix a win32 error due to portability, marcandre . lureau, 2023/03/13
- [PULL v2 24/25] qtest: enable vnc-display test on win32, marcandre . lureau, 2023/03/13
- [PULL v2 23/25] libqtest: make qtest_qmp_add_client work on win32, marcandre . lureau, 2023/03/13
- [PULL v2 25/25] monitor: restrict command getfd to POSIX hosts, marcandre . lureau, 2023/03/13
- Re: [PULL v2 00/25] Win socket patches, Peter Maydell, 2023/03/13