From nobody Wed Apr 16 03:52:38 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504836639583315.03100967118723; Thu, 7 Sep 2017 19:10:39 -0700 (PDT) Received: from localhost ([::1]:42965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq8kg-0006yZ-IG for importer@patchew.org; Thu, 07 Sep 2017 22:10:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq8gM-0003Iy-Ck for qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq8gH-0002HI-NY for qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50558) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dq8gH-0002Ga-Gy for qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:06:05 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91EF5821C7; Fri, 8 Sep 2017 02:06:04 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADD2D600C2; Fri, 8 Sep 2017 02:05:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91EF5821C7 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jasowang@redhat.com From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Fri, 8 Sep 2017 10:05:14 +0800 Message-Id: <1504836324-4871-9-git-send-email-jasowang@redhat.com> In-Reply-To: <1504836324-4871-1-git-send-email-jasowang@redhat.com> References: <1504836324-4871-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 08 Sep 2017 02:06:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/18] net/socket: Don't treat odd socket type as SOCK_STREAM 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: Mao Zhongyi , jasowang@redhat.com, armbru@redhat.com 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" From: Mao Zhongyi In net_socket_fd_init(), the 'default' case is odd: it warns, then continues as if the socket type was SOCK_STREAM. The comment explains "this could be a eg. a pty", but that makes no sense. If @fd really was a pty, getsockopt() would fail with ENOTSOCK. If @fd was a socket, but neither SOCK_DGRAM nor SOCK_STREAM. It should not be treated as if it was SOCK_STREAM. Turn this case into an Error. If there is a genuine reason to support something like SOCK_RAW, it should be explicitly handled. Cc: jasowang@redhat.com Cc: armbru@redhat.com Cc: berrange@redhat.com Cc: armbru@redhat.com Cc: eblake@redhat.com Suggested-by: Markus Armbruster Suggested-by: Daniel P. Berrange Signed-off-by: Mao Zhongyi Reviewed-by: Markus Armbruster Signed-off-by: Jason Wang --- net/socket.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/socket.c b/net/socket.c index 18af2ab..b4c5a04 100644 --- a/net/socket.c +++ b/net/socket.c @@ -448,9 +448,9 @@ static NetSocketState *net_socket_fd_init(NetClientStat= e *peer, case SOCK_STREAM: return net_socket_fd_init_stream(peer, model, name, fd, is_connect= ed); default: - /* who knows ... this could be a eg. a pty, do warn and continue a= s stream */ - fprintf(stderr, "qemu: warning: socket type=3D%d for fd=3D%d is no= t SOCK_DGRAM or SOCK_STREAM\n", so_type, fd); - return net_socket_fd_init_stream(peer, model, name, fd, is_connect= ed); + error_report("socket type=3D%d for fd=3D%d must be either" + " SOCK_DGRAM or SOCK_STREAM", so_type, fd); + closesocket(fd); } return NULL; } --=20 2.7.4