From patchwork Sun May 20 06:15:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 136413 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3157620lji; Sat, 19 May 2018 23:57:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpVcIRd6pHWOUHBMKZYpPDp4JBYSzXUsvM5wEq2KBRKkGDY2F/7w5Q7cqbYEuKSWQ5bgz2+ X-Received: by 2002:a0c:dc0c:: with SMTP id s12-v6mr14305132qvk.130.1526799443511; Sat, 19 May 2018 23:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526799443; cv=none; d=google.com; s=arc-20160816; b=GlydPI+xrhkZnlx0md19UWmLrQOVF/X1V8ESnvxfsL58Lcf+8CAMRmrzoz44fp3end cX2hpaCh7UXnPqBemfwet2+p/PRJaq7ToBxE2zpXNlJH6Ec6GTr2LeQ/vd8RXbm9gq05 lX6TfPpRO4P838sUjcG8dxLFRIoxs2u0j0Uc6jpINXWryWhokW4Zuuk3TWmiQncNq/9K 4+PdBaP/UwFS+A0wqzuMhYJVYmbA95jyvJozQO+YsP3yBpUrq5sGGnBs8AI0A5Pz7XS2 na42KfGSgrg4UBvlc0niU2Jk+K2E1QyNWD9ULZl8+XUCEVRtoo5mKhbPygm03Plxspej qBKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=53ymkacw1nI9Vn2qIyvaE69qg03xkB7peyiEMBy6Qx4=; b=b9dc4WF/CVtQZ5PR2D/I+Dr36HAMkQNTxdzcDSeITATg62T4Fg44PRmUt56lF9S7v8 fSllFZUB7ZYKYBssBmuDp33hCmOAi22BQsE65tzOL17u4IaA/xGE7IxM+5ycAsOO+Iej GBUBwl1SOn3dVdl5ew1xguNWIdd/LjvREyf/A1+44uXCv8V+4cXT/zTfri+qXtwzWol+ GPJM2zhT8iHorMuqDPjsP6o8euid1xXwoQCvIXZ8aaec7FL2rpYLagR/Y/t51C5fev+4 4CDyVX93FJdcy8jptz7JnuVQDwb2dZGVPvH5lodP3tAPTaQ10TxkRBQX1ewirbJsZz3+ tUXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q46-v6si3873509qtb.16.2018.05.19.23.57.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 19 May 2018 23:57:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:45409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKIHS-0001ME-Us for patch@linaro.org; Sun, 20 May 2018 02:57:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKIEY-0007pH-KG for qemu-devel@nongnu.org; Sun, 20 May 2018 02:54:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKIEV-0002KB-JH for qemu-devel@nongnu.org; Sun, 20 May 2018 02:54:22 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:60971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKIEV-0002Je-BB; Sun, 20 May 2018 02:54:19 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 4A66E4112D; Sun, 20 May 2018 09:54:18 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id 1F9C310CD; Sun, 20 May 2018 09:15:14 +0300 (MSK) Received: (nullmailer pid 7410 invoked by uid 1000); Sun, 20 May 2018 06:15:12 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Sun, 20 May 2018 09:15:05 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 19/22] 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: qemu-trivial@nongnu.org, Peter Maydell , Michael Tokarev Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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é Reviewed-by: Thomas Huth Signed-off-by: Michael Tokarev --- gdbstub.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) -- 2.11.0 diff --git a/gdbstub.c b/gdbstub.c index 9682e16ef7..b99980d2e2 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1828,9 +1828,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; } } @@ -1857,9 +1855,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 Sun May 20 06:15:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 136412 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3139764lji; Sat, 19 May 2018 23:29:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZruFkJhVgo5GOkobhY6cVfgentWGRP1nF/GcuJQVJQM53i3ej+ySvm6cwYoKmKUDbPVDUR7 X-Received: by 2002:ac8:3488:: with SMTP id w8-v6mr15173428qtb.278.1526797749553; Sat, 19 May 2018 23:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526797749; cv=none; d=google.com; s=arc-20160816; b=iMm3mRLApQf5ENGE0Y31unBSPdqDM1vC34O7dvB3q+tv62xRBRg31sDlWnrCq0So/l Qgk7PgDYwBwmrcF1vgc24yRPRoY5ufjtRyX2K06L7dD6hJMfb6l90znMtYYfDCcgDdto JbVa3tw8dQ577nf53CrJDnRFzvUHr9FJ8+aM5UijszNMybDwWKMJwt9ZUFxp30RKGjbc C3eVbZDevlX6FXdu6jZrpsii6x1pWEeZ5hUBbvsI8dMXN7D9BBKWlZ/Uo9PhhkiJqGj8 Pl+IVKl4T87ywy9zNXE7sgnWHLuHObQI8jEXvzi1gGQaYt/i3v21KWauJKb9pIxQehcx s0OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=8xAqIGNk7dSi1cFTmDZObSE6O1hCy4Oac2y2Vm9b4ds=; b=vijERiPMwmFQ9DdjyjCRMULDsRsb9g0ghhBsYKPLuG5EiOY78UkXxdxBznHZZcaAA1 szKFGzYKzKn8JEU1qzqvshEdcEztrMUR9W1/5wnnQTzFVRqlTFSbsRWpUTebDI43AbjG knqqEZCTRaaPbDCGox0L44nF2f/pd2TXmE8TMWuR5Anuhwih6GsUM83R6kW4+vsIXry8 4jDbupOgnRpuJxd9VThS1VjIJrx3BTtvY6c9URy2vaG+wyHYiyC7ENpJYvtcs9l1eg8F 7W1zSR0AnoQ+iyACsRLDK67cjm9apOkVCCtdJl0tKWc6+IHwPbNwmrH40IQIXVVJczSP 0iMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v42-v6si7070139qtc.287.2018.05.19.23.29.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 19 May 2018 23:29:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:45326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKHq8-00034J-Un for patch@linaro.org; Sun, 20 May 2018 02:29:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKHlW-0007n5-RP for qemu-devel@nongnu.org; Sun, 20 May 2018 02:24:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKHlT-0008JR-Mj for qemu-devel@nongnu.org; Sun, 20 May 2018 02:24:22 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:51493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKHlT-0008JB-EO; Sun, 20 May 2018 02:24:19 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id B630B4111D; Sun, 20 May 2018 09:24:18 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id DC79610CB; Sun, 20 May 2018 09:15:13 +0300 (MSK) Received: (nullmailer pid 7412 invoked by uid 1000); Sun, 20 May 2018 06:15:12 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Sun, 20 May 2018 09:15:06 +0300 Message-Id: <2f652224f76c115f6c991766b7acac1e22580954.1526796813.git.mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 20/22] 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: qemu-trivial@nongnu.org, Peter Maydell , Michael Tokarev Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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é Reviewed-by: Thomas Huth Signed-off-by: Michael Tokarev --- gdbstub.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) -- 2.11.0 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; + } 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; }