From nobody Wed Oct 29 23:02:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526319284976550.7105760624269; Mon, 14 May 2018 10:34:44 -0700 (PDT) Received: from localhost ([::1]:47454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIHMt-0000pg-7W for importer@patchew.org; Mon, 14 May 2018 13:34:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIHJJ-0007AD-1N for qemu-devel@nongnu.org; Mon, 14 May 2018 13:30:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIHJI-00066v-8F for qemu-devel@nongnu.org; Mon, 14 May 2018 13:30:57 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:41642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIHJI-0005yO-1U; Mon, 14 May 2018 13:30:56 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1fIHJ8-0000I7-E3; Mon, 14 May 2018 18:30:46 +0100 From: Peter Maydell To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Date: Mon, 14 May 2018 18:30:43 +0100 Message-Id: <20180514173044.5025-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514173044.5025-1-peter.maydell@linaro.org> References: <20180514173044.5025-1-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 1/2] gdbstub: Use qemu_set_cloexec() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use the utility routine qemu_set_cloexec() rather than manually calling fcntl(). This lets us drop the #ifndef _WIN32 guards and also means Coverity doesn't complain that we're ignoring the fcntl error return (CID 1005665, CID 1005667). Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth --- gdbstub.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 3c3807358c..cc7626c790 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1818,9 +1818,7 @@ static void gdb_accept(void) perror("accept"); return; } else if (fd >=3D 0) { -#ifndef _WIN32 - fcntl(fd, F_SETFD, FD_CLOEXEC); -#endif + qemu_set_cloexec(fd); break; } } @@ -1847,9 +1845,7 @@ static int gdbserver_open(int port) perror("socket"); return -1; } -#ifndef _WIN32 - fcntl(fd, F_SETFD, FD_CLOEXEC); -#endif + qemu_set_cloexec(fd); =20 socket_set_fast_reuse(fd); =20 --=20 2.17.0 From nobody Wed Oct 29 23:02:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1526319155152569.6164429589847; Mon, 14 May 2018 10:32:35 -0700 (PDT) Received: from localhost ([::1]:47445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIHKs-0007yD-B7 for importer@patchew.org; Mon, 14 May 2018 13:32:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIHJI-00079z-1H for qemu-devel@nongnu.org; Mon, 14 May 2018 13:30:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIHJH-00065q-A9 for qemu-devel@nongnu.org; Mon, 14 May 2018 13:30:56 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:41642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIHJH-0005yO-3A; Mon, 14 May 2018 13:30:55 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1fIHJ9-0000IO-3t; Mon, 14 May 2018 18:30:47 +0100 From: Peter Maydell To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Date: Mon, 14 May 2018 18:30:44 +0100 Message-Id: <20180514173044.5025-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514173044.5025-1-peter.maydell@linaro.org> References: <20180514173044.5025-1-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 2/2] gdbstub: Handle errors in gdb_accept() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth --- gdbstub.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index cc7626c790..7c2bceb040 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1804,7 +1804,7 @@ void gdb_signalled(CPUArchState *env, int sig) put_packet(s, buf); } =20 -static void gdb_accept(void) +static bool gdb_accept(void) { GDBState *s; struct sockaddr_in sockaddr; @@ -1816,7 +1816,7 @@ static void gdb_accept(void) fd =3D accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len); if (fd < 0 && errno !=3D EINTR) { perror("accept"); - return; + return false; } else if (fd >=3D 0) { qemu_set_cloexec(fd); break; @@ -1824,7 +1824,10 @@ static void gdb_accept(void) } =20 /* set short latency */ - socket_set_nodelay(fd); + if (socket_set_nodelay(fd)) { + perror("setsockopt"); + return false; + } =20 s =3D g_malloc0(sizeof(GDBState)); s->c_cpu =3D first_cpu; @@ -1833,6 +1836,7 @@ static void gdb_accept(void) gdb_has_xml =3D false; =20 gdbserver_state =3D s; + return true; } =20 static int gdbserver_open(int port) @@ -1873,7 +1877,11 @@ int gdbserver_start(int port) if (gdbserver_fd < 0) return -1; /* accept connections */ - gdb_accept(); + if (!gdb_accept()) { + close(gdbserver_fd); + gdbserver_fd =3D -1; + return -1; + } return 0; } =20 --=20 2.17.0