From nobody Sat Nov 1 22:15:44 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527684902182667.6953234621723; Wed, 30 May 2018 05:55:02 -0700 (PDT) Received: from localhost ([::1]:38495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fO0cp-0002Jg-W3 for importer@patchew.org; Wed, 30 May 2018 08:54:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fO0bw-0001xs-Uj for qemu-devel@nongnu.org; Wed, 30 May 2018 08:53:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fO0bs-00043j-Q7 for qemu-devel@nongnu.org; Wed, 30 May 2018 08:53:53 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:51678) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fO0bs-00042O-JJ for qemu-devel@nongnu.org; Wed, 30 May 2018 08:53:48 -0400 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Wed, 30 May 2018 14:53:44 +0200 From: Fei Li To: qemu-devel@nongnu.org Date: Wed, 30 May 2018 20:53:14 +0800 Message-Id: <20180530125314.11677-1-fli@suse.com> X-Mailer: git-send-email 2.13.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH] fix Segmentation fault when emulating a bluetooth device 'dev' 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: , 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" The current code bt_hid_send_data() did not check whether its first parameter *ch is NULL, which will cause a "Segmentation fault" when *ch is NULL as ch->remote_mtu will be directly referenced later in this function. E.g. when called by bt_hid_datain() and hid->interrupt is NULL with "qemu-system-x86_64 ... \ -bt device:keyboard,vlan=3D3". Thus add a judgement to avoid such error. Signed-off-by: Fei Li --- hw/bt/hid.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/bt/hid.c b/hw/bt/hid.c index 056291f9b5..dfb0ea9c9b 100644 --- a/hw/bt/hid.c +++ b/hw/bt/hid.c @@ -174,6 +174,9 @@ static void bt_hid_send_data(struct bt_l2cap_conn_param= s_s *ch, int type, uint8_t *pkt, hdr =3D (BT_DATA << 4) | type; int plen; =20 + if (!ch) + return; + do { plen =3D MIN(len, ch->remote_mtu - 1); pkt =3D ch->sdu_out(ch, plen + 1); --=20 2.13.6