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; }