[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 5/9] qmp: 'add_client' actually expects sockets
From: |
marcandre . lureau |
Subject: |
[PATCH v2 5/9] qmp: 'add_client' actually expects sockets |
Date: |
Sun, 29 Jan 2023 22:24:10 +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>
---
monitor/qmp-cmds.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index bf22a8c5a6..01cfc23407 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -22,6 +22,7 @@
#include "sysemu/sysemu.h"
#include "qemu/config-file.h"
#include "qemu/uuid.h"
+#include "qemu/sockets.h"
#include "chardev/char.h"
#include "sysemu/kvm.h"
#include "sysemu/runstate.h"
@@ -190,11 +191,17 @@ 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;
+ }
+
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,
has_tls, tls, errp)) {
- close(fd);
+ closesocket(fd);
}
return;
}
@@ -203,12 +210,12 @@ void qmp_add_client(const char *protocol, const char
*fdname,
s = qemu_chr_find(protocol);
if (!s) {
error_setg(errp, "protocol '%s' is invalid", protocol);
- close(fd);
+ closesocket(fd);
return;
}
if (qemu_chr_add_client(s, fd) < 0) {
error_setg(errp, "failed to add client");
- close(fd);
+ closesocket(fd);
return;
}
}
--
2.39.1
- [PATCH v2 0/9] Various win32 fixes & teach 'getfd' QMP command to import sockets, marcandre . lureau, 2023/01/29
- [PATCH v2 1/9] tests: fix path separator, use g_build_filename(), marcandre . lureau, 2023/01/29
- [PATCH v2 2/9] tests: fix test-io-channel-command on win32, marcandre . lureau, 2023/01/29
- [PATCH v2 3/9] tests/docker: fix a win32 error due to portability, marcandre . lureau, 2023/01/29
- [PATCH v2 4/9] osdep: implement qemu_socketpair() for win32, marcandre . lureau, 2023/01/29
- [PATCH v2 5/9] qmp: 'add_client' actually expects sockets,
marcandre . lureau <=
- [PATCH v2 6/9] qapi: implement conditional command arguments, marcandre . lureau, 2023/01/29
- [PATCH v2 9/9] qtest: enable vnc-display test on win32, marcandre . lureau, 2023/01/29
- [PATCH v2 7/9] qmp: teach 'getfd' to import sockets on win32, marcandre . lureau, 2023/01/29
- [PATCH v2 8/9] libqtest: make qtest_qmp_add_client work on win32, marcandre . lureau, 2023/01/29