Skip to contentSkip to conversation

monitor: check for readline in monitor_event()

Qemu-devel Luiz Capitulino 2 participants 5 messages Jun 15, 2009 – Jun 16, 2009

lore
Share & tools
lore
#0 lore raw

The call of readline_show_prompt() in CHR_EVENT_RESET's body will trig a segfault if readline is not being used, because 'mon->rs' will be NULL.

This fixes the problem by adding the proper check.

I've trigged this while playing with an off-tree code that disables readline support, I'm not sure whether in-tree code can trig this.

---
 monitor.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
monitor.c +1 -1
index 6b45f6c..787101d 100644
@@ -3002,7 +3002,7 @@ static void monitor_event(void *opaque, int event)
     case CHR_EVENT_RESET:
         monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
                        "information\n", QEMU_VERSION);
-        if (mon->chr->focus == 0)
+        if (mon->rs && mon->chr->focus == 0)
             readline_show_prompt(mon->rs);
         break;
     }
Signature · 1 line
1.6.3.GIT
#1 lore raw
Quoted 19 lines · Luiz Capitulino

The call of readline_show_prompt() in CHR_EVENT_RESET's body will trig a segfault if readline is not being used, because 'mon->rs' will be NULL.

This fixes the problem by adding the proper check.

I've trigged this while playing with an off-tree code that disables readline support, I'm not sure whether in-tree code can trig this.

---
 monitor.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
monitor.c +0 -0
index 6b45f6c..787101d 100644

monitor.c static void monitor_event(void *opaque, int event) · line 3008

Quoted 8 lines
monitor.c +1 -1
@@ -3002,7 +3002,7 @@ static void monitor_event(void *opaque, int event)
     case CHR_EVENT_RESET:
         monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
                        "information\n", QEMU_VERSION);
-        if (mon->chr->focus == 0)
+        if (mon->rs && mon->chr->focus == 0)
             readline_show_prompt(mon->rs);
         break;
     }

In-tree code is not affected as no monitor user will call qemu_chr_reset for the associated char device if there is no readline active as well. Yeah, secret de-facto rule.

The patch is not incorrect, but I would like to understand the out-of-tree use case behind it. So you do want the info line printed, but provide your own readline processor? What kind of terminal is this?

Jan

#2 lore raw
Quoted 24 lines · On Tue, 16 Jun 2009 00:42:26 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 23 lines · Luiz Capitulino

The call of readline_show_prompt() in CHR_EVENT_RESET's body will trig a segfault if readline is not being used, because 'mon->rs' will be NULL.

This fixes the problem by adding the proper check.

I've trigged this while playing with an off-tree code that disables readline support, I'm not sure whether in-tree code can trig this.

---
 monitor.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
monitor.c +0 -0
index 6b45f6c..787101d 100644
@@ -3002,7 +3002,7 @@ static void monitor_event(void *opaque, int

event) case CHR_EVENT_RESET:
monitor_printf(mon, "QEMU %s monitor - type 'help' for
more " "information\n", QEMU_VERSION);
- if (mon->chr->focus == 0)

Quoted 8 lines
Quoted 4 lines

+ if (mon->rs && mon->chr->focus == 0)

             readline_show_prompt(mon->rs);
         break;
     }

In-tree code is not affected as no monitor user will call qemu_chr_reset for the associated char device if there is no readline active as well. Yeah, secret de-facto rule.

Ok.

Quoted 4 lines

The patch is not incorrect, but I would like to understand the out-of-tree use case behind it. So you do want the info line printed, but provide your own readline processor? What kind of terminal is this?

I'm working on a machine-friendly monitor for QEMU, which disables
readline.

I didn't want to get into the details now, it will be better to
discuss the prototype I'm writing, should be finished soon.

#3 lore raw
Quoted 37 lines · Luiz Capitulino
Quoted 15 lines · On Tue, 16 Jun 2009 00:42:26 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 14 lines · Luiz Capitulino

The call of readline_show_prompt() in CHR_EVENT_RESET's body will trig a segfault if readline is not being used, because 'mon->rs' will be NULL.

This fixes the problem by adding the proper check.

I've trigged this while playing with an off-tree code that disables readline support, I'm not sure whether in-tree code can trig this.

---
 monitor.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 16 lines

monitor.c static void monitor_event(void *opaque, int event) · line 3008

Quoted 13 lines
monitor.c +0 -0
index 6b45f6c..787101d 100644
@@ -3002,7 +3002,7 @@ static void monitor_event(void *opaque, int

event) case CHR_EVENT_RESET:
monitor_printf(mon, "QEMU %s monitor - type 'help' for
more " "information\n", QEMU_VERSION);

monitor.c +1 -1
-        if (mon->chr->focus == 0)
+        if (mon->rs && mon->chr->focus == 0)
             readline_show_prompt(mon->rs);
         break;
     }

In-tree code is not affected as no monitor user will call qemu_chr_reset for the associated char device if there is no readline active as well. Yeah, secret de-facto rule.

Ok.

Quoted 7 lines
Quoted 4 lines

The patch is not incorrect, but I would like to understand the out-of-tree use case behind it. So you do want the info line printed, but provide your own readline processor? What kind of terminal is this?

I'm working on a machine-friendly monitor for QEMU, which disables
readline.

Again, I bet that your monitor will not be interested in the prompt header. So I think we should rather exclude the whole CHR_EVENT_RESET path for the !mon->rs case.

Quoted 3 lines

I didn't want to get into the details now, it will be better to
discuss the prototype I'm writing, should be finished soon.

Looking forward!

Jan

#4 lore raw
Quoted 44 lines · On Tue, 16 Jun 2009 17:46:05 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 43 lines · Luiz Capitulino
Quoted 16 lines · On Tue, 16 Jun 2009 00:42:26 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 15 lines · Luiz Capitulino

The call of readline_show_prompt() in CHR_EVENT_RESET's body will trig a segfault if readline is not being used, because 'mon->rs' will be NULL.

This fixes the problem by adding the proper check.

I've trigged this while playing with an off-tree code that disables readline support, I'm not sure whether in-tree code can trig this.

---
 monitor.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 16 lines

monitor.c static void monitor_event(void *opaque, int event) · line 3008

Quoted 13 lines
monitor.c +0 -0
index 6b45f6c..787101d 100644
@@ -3002,7 +3002,7 @@ static void monitor_event(void *opaque, int

event) case CHR_EVENT_RESET:
monitor_printf(mon, "QEMU %s monitor - type 'help' for
more " "information\n", QEMU_VERSION);

monitor.c +1 -1
-        if (mon->chr->focus == 0)
+        if (mon->rs && mon->chr->focus == 0)
             readline_show_prompt(mon->rs);
         break;
     }

In-tree code is not affected as no monitor user will call qemu_chr_reset for the associated char device if there is no readline active as well. Yeah, secret de-facto rule.

Ok.

Quoted 4 lines

The patch is not incorrect, but I would like to understand the out-of-tree use case behind it. So you do want the info line printed, but provide your own readline processor? What kind of terminal is this?

Quoted 6 lines
Quoted 2 lines

I'm working on a machine-friendly monitor for QEMU, which disables
readline.

Again, I bet that your monitor will not be interested in the prompt header. So I think we should rather exclude the whole CHR_EVENT_RESET path for the !mon->rs case.

It has a greeting message, although my real question is whether it's
going to support the mux part or not. If it's not, then I can have my own reset handler.

Ouch, I said I didn't want to get into details. :)

Quoted 4 lines
Quoted 2 lines

I didn't want to get into the details now, it will be better to
discuss the prototype I'm writing, should be finished soon.

Looking forward!

Great, will appreciate your feedback.