Skip to contentSkip to conversation

input: mouse_set should check input device type.

PATCH Superseded Hani Benhabiles 3 participants 4 messages Mar 30, 2014 – Mar 31, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: mouse_set should check input device type.

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

---
 ui/input.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
ui/input.c +11 -4
index 2761911..013de95 100644
@@ -342,11 +342,18 @@ 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))) {
+            monitor_printf(mon, "Input device '%s' is not a mouse",
+                           s->handler->name);
+            return;
+        }
+        found = 1;
+        qemu_input_handler_activate(s);
+        break;
     }
 
     if (!found) {
Signature · 1 line
1.8.3.2
#1 lore raw

ui/input.c void do_mouse_set(Monitor *mon, const QDict *qdict) · line 351

Quoted 5 lines
ui/input.c +4 -0
+        if (!(s->handler->mask & (INPUT_EVENT_MASK_REL |
+                                  INPUT_EVENT_MASK_ABS))) {
+            monitor_printf(mon, "Input device '%s' is not a mouse",
+                           s->handler->name);

That should be error_report (I think, Markus?).

Otherwise the patch is fine.

cheers,
Gerd

#2 lore raw
Quoted 6 lines · Gerd Hoffmann

ui/input.c void do_mouse_set(Monitor *mon, const QDict *qdict) · line 351

Quoted 4 lines
ui/input.c +4 -0
+        if (!(s->handler->mask & (INPUT_EVENT_MASK_REL |
+                                  INPUT_EVENT_MASK_ABS))) {
+            monitor_printf(mon, "Input device '%s' is not a mouse",
+                           s->handler->name);

That should be error_report (I think, Markus?).

Yes, please. Same for the "Mouse at given index not found\n" message further down. Note that error_report() does *not* want \n.

Quoted 5 lines

Otherwise the patch is fine.

cheers,
Gerd

#3 lore raw
Quoted 11 lines · Markus Armbruster
Quoted 6 lines · Gerd Hoffmann

ui/input.c void do_mouse_set(Monitor *mon, const QDict *qdict) · line 351

Quoted 4 lines
ui/input.c +4 -0
+        if (!(s->handler->mask & (INPUT_EVENT_MASK_REL |
+                                  INPUT_EVENT_MASK_ABS))) {
+            monitor_printf(mon, "Input device '%s' is not a mouse",
+                           s->handler->name);

That should be error_report (I think, Markus?).

Yes, please. Same for the "Mouse at given index not found\n" message further down. Note that error_report() does *not* want \n.

Ok, thanks.

I just followed the other monitor_printf() usage for consistency. v2 sent.

Quoted 6 lines
Quoted 6 lines

Otherwise the patch is fine.

cheers,
Gerd