From patchwork Mon Mar 31 22:09:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hani Benhabiles X-Patchwork-Id: 335620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E399B140082 for ; Tue, 1 Apr 2014 09:09:44 +1100 (EST) Received: from localhost ([::1]:51609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUkOk-0005ho-Se for incoming@patchwork.ozlabs.org; Mon, 31 Mar 2014 18:09:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUkOO-0005ey-Uk for qemu-devel@nongnu.org; Mon, 31 Mar 2014 18:09:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUkOI-0007Wl-VZ for qemu-devel@nongnu.org; Mon, 31 Mar 2014 18:09:20 -0400 Received: from mail-we0-x22e.google.com ([2a00:1450:400c:c03::22e]:34181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUkOI-0007Wh-Nk; Mon, 31 Mar 2014 18:09:14 -0400 Received: by mail-we0-f174.google.com with SMTP id t60so5330986wes.5 for ; Mon, 31 Mar 2014 15:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=BB7R2lXTm3BSqpyiuVxMmbZpkuO3qwPk1tqN3T8k1h0=; b=KJ/QRaZDRzvwW0KsyfN4ufBmIMReVNSMWkvnem5bjt2ENW4mhVzJ8VhGJK0CM2LJXi 2Bt48WV8650IlQ0VU4oYOwuRxrqXzuCCPIwd/VPN6BH8jamC5YyGRBHBcPuGHHYEgjhe 2GRS1K9VoMCr9WbItTwe73RWbuayrbR1fT3CyII3G7Ph6C+6m8VZtXWRORBWOnsJ8ZeH JzWyM62no7cySkqzBbedQpwYPzUkRNi2iyoZkJwFOXURorc/JKfvehPdH2tbtsx7lNUc ZMPdcNqc9yRDD9I6kNL9gJrq6koWrQUCqwUkuyi11yigQTJytYJaMxtSVJurhYyDTcxd ZaFQ== X-Received: by 10.194.201.73 with SMTP id jy9mr8977990wjc.51.1396303753870; Mon, 31 Mar 2014 15:09:13 -0700 (PDT) Received: from localhost.localdomain ([41.103.75.35]) by mx.google.com with ESMTPSA id q41sm36001745eez.7.2014.03.31.15.09.12 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 31 Mar 2014 15:09:13 -0700 (PDT) From: Hani Benhabiles To: qemu-devel@nongnu.org Date: Mon, 31 Mar 2014 23:09:06 +0100 Message-Id: <1396303746-1858-1-git-send-email-kroosec@gmail.com> X-Mailer: git-send-email 1.8.3.2 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::22e Cc: qemu-trivial@nongnu.org, kraxel@redhat.com, aliguori@amazon.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH v2] input: mouse_set should check input device type. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Otherwise, the index of an input device like a usb-kbd is silently accepted. (qemu) info mice Mouse #2: QEMU PS/2 Mouse * Mouse #3: QEMU HID Mouse (qemu) mouse_set 1 (qemu) info mice Mouse #2: QEMU PS/2 Mouse * Mouse #3: QEMU HID Mouse Also replace monitor_printf() call in do_mouse_set() with error_report() and adjust error message. Signed-off-by: Hani Benhabiles --- ui/input.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ui/input.c b/ui/input.c index 2761911..6e6a924 100644 --- a/ui/input.c +++ b/ui/input.c @@ -342,15 +342,21 @@ void do_mouse_set(Monitor *mon, const QDict *qdict) int found = 0; QTAILQ_FOREACH(s, &handlers, node) { - if (s->id == index) { - found = 1; - qemu_input_handler_activate(s); - break; + if (s->id != index) { + continue; } + if (!(s->handler->mask & (INPUT_EVENT_MASK_REL | + INPUT_EVENT_MASK_ABS))) { + error_report("Input device '%s' is not a mouse", s->handler->name); + return; + } + found = 1; + qemu_input_handler_activate(s); + break; } if (!found) { - monitor_printf(mon, "Mouse at given index not found\n"); + error_report("Mouse at index '%d' not found", index); } qemu_input_check_mode_change();