From: Paolo Bonzini <pbonzini@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-trivial] [Qemu-devel] [PULL 20/22] gdbstub: Handle errors in gdb_accept()
Date: Thu, 24 May 2018 23:35:02 +0200 [thread overview]
Message-ID: <d3acfa93-ee93-fce8-36bb-f481637b0140@redhat.com> (raw)
In-Reply-To: <2f652224f76c115f6c991766b7acac1e22580954.1526796813.git.mjt@msgid.tls.msk.ru>
On 20/05/2018 08:15, Michael Tokarev wrote:
> From: Peter Maydell <peter.maydell@linaro.org>
>
> In gdb_accept(), we both fail to check all errors (notably
> that from socket_set_nodelay(), as Coverity notes in CID 1005666),
> and fail to return an error status back to our caller. Correct
> both of these things, so that errors in accept() result in our
> stopping with a useful error message rather than ignoring it.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> gdbstub.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index b99980d2e2..e4ece2f5bc 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1814,7 +1814,7 @@ void gdb_signalled(CPUArchState *env, int sig)
> put_packet(s, buf);
> }
>
> -static void gdb_accept(void)
> +static bool gdb_accept(void)
> {
> GDBState *s;
> struct sockaddr_in sockaddr;
> @@ -1826,7 +1826,7 @@ static void gdb_accept(void)
> fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
> if (fd < 0 && errno != EINTR) {
> perror("accept");
> - return;
> + return false;
> } else if (fd >= 0) {
> qemu_set_cloexec(fd);
> break;
> @@ -1834,7 +1834,10 @@ static void gdb_accept(void)
> }
>
> /* set short latency */
> - socket_set_nodelay(fd);
> + if (socket_set_nodelay(fd)) {
> + perror("setsockopt");
> + return false;
Coverity notes that this leaks fd.
Paolo
> + }
>
> s = g_malloc0(sizeof(GDBState));
> s->c_cpu = first_cpu;
> @@ -1843,6 +1846,7 @@ static void gdb_accept(void)
> gdb_has_xml = false;
>
> gdbserver_state = s;
> + return true;
> }
>
> static int gdbserver_open(int port)
> @@ -1883,7 +1887,11 @@ int gdbserver_start(int port)
> if (gdbserver_fd < 0)
> return -1;
> /* accept connections */
> - gdb_accept();
> + if (!gdb_accept()) {
> + close(gdbserver_fd);
> + gdbserver_fd = -1;
> + return -1;
> + }
> return 0;
> }
>
>
next prev parent reply other threads:[~2018-05-24 21:35 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-20 6:14 [Qemu-trivial] [PULL 00/22] Trivial patches for 2018-05-20 Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 01/22] tcg: fix s/compliment/complement/ typos Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 02/22] misc, ide: remove use of HWADDR_PRIx in trace events Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 03/22] slirp/debug: Print IP addresses in human readable form Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 04/22] qemu-option-trace: -trace enable= is a pattern, not a file Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 05/22] HACKING: document preference for g_new instead of g_malloc Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 06/22] qemu-img-commands.hx: argument ordering fixups Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 07/22] qemu-img.texi: fix command ordering Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 08/22] qemu-img: remove references to GEN_DOCS Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 09/22] qemu-img: Make documentation between .texi and .hx consistent Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 10/22] qemu-img-cmds.hx: add passive-aggressive note Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 11/22] hw/ide/ahci: Keep ALLWINNER_AHCI() macro internal Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 12/22] tests: fix tpm-crb tpm-tis tests race Michael Tokarev
2018-05-20 6:14 ` [Qemu-trivial] [PULL 13/22] trivial: Do not include pci.h if it is not necessary Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 14/22] Remove unnecessary variables for function return value Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 15/22] hw/timer/mt48t59: Fix bit-rotten NVRAM_PRINTF format strings Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 16/22] qemu-options: Allow -no-user-config again Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 17/22] typedefs: Remove PcGuestInfo from qemu/typedefs.h Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 18/22] replace functions which are only available in glib-2.24 Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 19/22] gdbstub: Use qemu_set_cloexec() Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 20/22] gdbstub: Handle errors in gdb_accept() Michael Tokarev
2018-05-24 21:35 ` Paolo Bonzini [this message]
2018-05-24 22:23 ` [Qemu-trivial] [Qemu-devel] " Philippe Mathieu-Daudé
2018-05-20 6:15 ` [Qemu-trivial] [PULL 21/22] qapi/net.json: Fix the version number of the "vlan" removal Michael Tokarev
2018-05-20 6:15 ` [Qemu-trivial] [PULL 22/22] acpi: fix a comment about aml_call0() Michael Tokarev
2018-05-21 12:22 ` [Qemu-trivial] [Qemu-devel] [PULL 00/22] Trivial patches for 2018-05-20 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d3acfa93-ee93-fce8-36bb-f481637b0140@redhat.com \
--to=pbonzini@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).