Skip to contentSkip to conversation

console: Avoid dereferencing NULL active_console

PATCH Applied Stefan Hajnoczi 4 participants 4 messages Sep 20, 2010 – Oct 3, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 console: Avoid dereferencing NULL active_console

The console_select() function does not check that active_console is non-NULL before dereferencing it. When invoked with qemu -nodefaults it is possible to hit this case.

This patch checks that active_console is non-NULL before stashing away the old console dimensions in console_select().

---
 console.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
console.c +4 -2
index 698bc10..c1728b1 100644
@@ -1060,8 +1060,10 @@ void console_select(unsigned int index)
 
     if (index >= MAX_CONSOLES)
         return;
-    active_console->g_width = ds_get_width(active_console->ds);
-    active_console->g_height = ds_get_height(active_console->ds);
+    if (active_console) {
+        active_console->g_width = ds_get_width(active_console->ds);
+        active_console->g_height = ds_get_height(active_console->ds);
+    }
     s = consoles[index];
     if (s) {
         DisplayState *ds = s->ds;
Signature · 1 line
1.7.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Stefan Hajnoczi

The console_select() function does not check that active_console is non-NULL before dereferencing it. When invoked with qemu -nodefaults it is possible to hit this case.

This patch checks that active_console is non-NULL before stashing away the old console dimensions in console_select().

Looks sane to me, simliar tests exist in other places.

cheers,
Gerd

Acked-by on v1 1/1
#2 lore raw
In reply to Stefan Hajnoczi

Am 20.09.2010 15:11, schrieb Stefan Hajnoczi:

Quoted 19 lines

The console_select() function does not check that active_console is non-NULL before dereferencing it. When invoked with qemu -nodefaults it is possible to hit this case.

This patch checks that active_console is non-NULL before stashing away the old console dimensions in console_select().

---
console.c | 6 ++++--

1 files changed, 4 insertions(+), 2 deletions(-)
console.c +0 -0
index 698bc10..c1728b1 100644
@@ -1060,8 +1060,10 @@ void console_select(unsigned int index)
 
 if (index >= MAX_CONSOLES)

console.c void console_select(unsigned int index) · line 1069

Quoted 10 lines
console.c +4 -2
 return;
- active_console->g_width = ds_get_width(active_console->ds);
- active_console->g_height = ds_get_height(active_console->ds);
+ if (active_console) {
+ active_console->g_width = ds_get_width(active_console->ds);
+ active_console->g_height = ds_get_height(active_console->ds);
+ }
 s = consoles[index];
 if (s) {
 DisplayState *ds = s->ds;

To avoid that still more people fix the same bug,
I'd appreciate shorter commit times for simple patches like this one.

Cheers,
Stefan

Applied
#3 lore raw
In reply to Stefan Hajnoczi

Thanks, applied.

Quoted 34 lines · Stefan Hajnoczi

The console_select() function does not check that active_console is non-NULL before dereferencing it.  When invoked with qemu -nodefaults it is possible to hit this case.

This patch checks that active_console is non-NULL before stashing away the old console dimensions in console_select().

---
 console.c |    6 ++++--

 1 files changed, 4 insertions(+), 2 deletions(-)
console.c +4 -3
index 698bc10..c1728b1 100644
@@ -1060,8 +1060,10 @@ void console_select(unsigned int index)
 
     if (index >= MAX_CONSOLES)
         return;
-    active_console->g_width = ds_get_width(active_console->ds);
-    active_console->g_height = ds_get_height(active_console->ds);
+    if (active_console) {
+        active_console->g_width = ds_get_width(active_console->ds);
+        active_console->g_height = ds_get_height(active_console->ds);
+    }
     s = consoles[index];
     if (s) {
         DisplayState *ds = s->ds;
--

1.7.1