Skip to contentSkip to conversation

monitor.c: Fix infinite loop in monitor's auto-complete

PATCH In review Dr. David Alan Gilbert (git) 2 participants 4 messages Feb 13, 2018 – Feb 16, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 monitor.c: Fix infinite loop in monitor's auto-complete

From: "Dr. David Alan Gilbert" <[email protected]>

Fixes 48fe86f6400574165979e0db6f5937ad487b6888
---
 monitor.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
monitor.c +4 -2
index 0c0faec0a4..bec484440f 100644
@@ -3696,7 +3696,7 @@ static void monitor_find_completion_by_table(Monitor *mon,
 {
     const char *cmdname;
     int i;
-    const char *ptype, *str, *name;
+    const char *ptype, *old_ptype, *str, *name;
     const mon_cmd_t *cmd;
     BlockBackend *blk = NULL;
 
@@ -3741,7 +3741,9 @@ static void monitor_find_completion_by_table(Monitor *mon,
             }
         }
         str = args[nb_args - 1];
-        while (*ptype == '-' && ptype[1] != '\0') {
+        old_ptype = NULL;
+        while (*ptype == '-' && old_ptype != ptype) {
+            old_ptype = ptype;
             ptype = next_arg_type(ptype);
         }
         switch(*ptype) {
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Please include the details of how to trigger this bug. This helps justify the patch as well as aiding anyone investigating/backporting the same issue in the future.

Aside from that:

#2 lore raw
Quoted 7 lines · * Stefan Hajnoczi ([email protected]) wrote:
Quoted 2 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Please include the details of how to trigger this bug. This helps justify the patch as well as aiding anyone investigating/backporting the same issue in the future.

OK, I'll include Dimitris's:
The QEMU monitor enters an infinite loop when trying to auto-complete commands that accept only optional parameters. The commands currently affected by this issue are 'info registers' and 'info mtree'.

Quoted 2 lines

Aside from that:

Thanks!

Dave

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 5 lines · * Dr. David Alan Gilbert (git) ([email protected]) wrote:

From: "Dr. David Alan Gilbert" <[email protected]>

Fixes 48fe86f6400574165979e0db6f5937ad487b6888

Queued.

Quoted 32 lines
---
 monitor.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
monitor.c +4 -2
index 0c0faec0a4..bec484440f 100644
@@ -3696,7 +3696,7 @@ static void monitor_find_completion_by_table(Monitor *mon,
 {
     const char *cmdname;
     int i;
-    const char *ptype, *str, *name;
+    const char *ptype, *old_ptype, *str, *name;
     const mon_cmd_t *cmd;
     BlockBackend *blk = NULL;
 
@@ -3741,7 +3741,9 @@ static void monitor_find_completion_by_table(Monitor *mon,
             }
         }
         str = args[nb_args - 1];
-        while (*ptype == '-' && ptype[1] != '\0') {
+        old_ptype = NULL;
+        while (*ptype == '-' && old_ptype != ptype) {
+            old_ptype = ptype;
             ptype = next_arg_type(ptype);
         }
         switch(*ptype) {
Signature · 1 line
2.14.3

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK