From patchwork Mon May 14 17:30:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 135755 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2066101lji; Mon, 14 May 2018 10:30:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqbKMkqfL1MRaVMyA5BHzD3VP9Zw3UX0Gp4N+mdTUXYOb2V19PkmTtuGHFVdjTpcHWE/eTw X-Received: by 2002:a19:1b11:: with SMTP id b17-v6mr9945655lfb.17.1526319047500; Mon, 14 May 2018 10:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526319047; cv=none; d=google.com; s=arc-20160816; b=zJYc45zC5/ueTSl5iu67GWzwqcvrL/VWpyWJIrCEEo6FRM67Vw+vPwesyTn22uh8VK SYfXdvWLivkXfJiz3A2KL+aRwYPdGDix5qA1ilFxp9wnNn6JmnjNuH509QgZsp5FEf2H AjVRP8mQ+SRbVo+xAR5ZGU721swYKKtdWpDmR2efUvp26mslxdPYxpXrtZmNCshV2fR/ ySHFsio2iA6L5zxN0H9VF8ghowHjsHdnsLt1BWJU1gBS+mZgbHhHp+r3kupop2yUK5GK tmaliUsg1Olww8OYZvYjovizF1X5QFXPQkS+OWL0ClcI3hwv3oVkR/nwxLXtcjLVA5BG AUOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=tF1NWEj9Czbu6vRxVisz2jpDcV0WhIknPCfl8aRUmxE=; b=eD9vFOvthJo0Xsu62h2t2Fgb6I7slUCfQiCXzCfXWv3WI9a4aGJp1f0CKz2AoG9zPf tugB4oLbC6z25Xs121EjFzxqMwkLO0qXEaWjg1yIiziYxzVr9jT/8uHyLG7qauIsZFxS s2KWA1gYoKW1hQ+5kmG4hp1nLzF5gFOSldknMcGp3flfEDNv/py+yJ4J9LC2Latb48d0 z4iVopinEqXZZP57nDtZHuF+iIOSKk5A5Bf2ATWTmyGHtwJ6/2jaJkljPfjkw7u9Qx+D dEBgMALqXBP0S/Td21hRC0pUJFZX4pKBc1NWgpdrFrWfN5L4aXACH3b/4VtPYaTxLcBG +SJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id q7-v6si4244200lfc.60.2018.05.14.10.30.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 10:30:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org Subject: [PATCH 1/2] gdbstub: Use qemu_set_cloexec() 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> 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 --- gdbstub.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) -- 2.17.0 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth 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 >= 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); socket_set_fast_reuse(fd); From patchwork Mon May 14 17:30:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 135756 Delivered-To: patches@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2066104lji; Mon, 14 May 2018 10:30:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoydD4/AafOGqy34juFL3rra5qinU0R2emrDRqvy9d+0xwRUxSh43g0mZDYXMZg1co/Boku X-Received: by 2002:a1c:b4e:: with SMTP id 75-v6mr5478362wml.32.1526319047562; Mon, 14 May 2018 10:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526319047; cv=none; d=google.com; s=arc-20160816; b=ZMtyvX2KmzlJAmtOvhzRRGWB47dIXcqW6v/cVSf7P7h0cWHtIl/5TkAnb0olArMesz X93qVi3D2M/niDuq90H/c5eOd9Ol93xvQwM8JfZuwPVsGSnuBzml2Va47ee815phhyfJ NE6jKnNdB1Hxaw/Aca6zSjpaoOjy2iu2zFC1SI26j9BnVcxG4zL4tjz53ySKbgHD1fWJ 4V3+iDgV9nvz9A+wEh9NMceifsMqIc+qbhFRWjBiNh86SVLE4e9nHd2HHQjCl+U2CVBa cFkeVhLNrdoWBobAP/L5OI1uSPm8LaSWsZ6ZwKhPCKwnPBtaxtO/t49RLW0kjFmqyCbe 9Bvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=xYIL9NHUnDI5GlwUhQUV8HUbcibE3bz6d3QYCrUhF3A=; b=cNsiYCvYTnMcmNiMTDoyXTTC3koJtqEcC9gWY87RYyIpZFysgpE8F9aZQHQ7mwqcQg xASeXcagtq0cyVnBn9YSew9Fh/0AD5YE5X3P8Ptbicl4rqYyteqnQLDf57eC4jc+jXjg pB7rHDZnjksp3G438fSgR+srUq9NvM2KVIu/bJfZSgPZ/igQ40oYY3vYVhAr1L4UxN6G MksU3oXzgAEfZ0KvgCQfYAghCy07wPfD8CHew/voW59iu7CXa3QMasQD9LtMpy5kEayN v/yVeK0/81RCB4JFOxvNq9qD8x0alL5u8Vrr3hHyxknF0c24vnSbH/dfhZ/axshtkcHD IHFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id m37-v6si8743264wrf.250.2018.05.14.10.30.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 10:30:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org Subject: [PATCH 2/2] gdbstub: Handle errors in gdb_accept() 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> 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 --- gdbstub.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) -- 2.17.0 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth 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); } -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 = 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; @@ -1824,7 +1824,10 @@ static void gdb_accept(void) } /* set short latency */ - socket_set_nodelay(fd); + if (socket_set_nodelay(fd)) { + perror("setsockopt"); + return false; + } s = g_malloc0(sizeof(GDBState)); s->c_cpu = first_cpu; @@ -1833,6 +1836,7 @@ static void gdb_accept(void) gdb_has_xml = false; gdbserver_state = s; + return true; } 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 = -1; + return -1; + } return 0; }