console: Avoid dereferencing NULL active_console
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
@@ -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
Quoted 6 lines · Stefan Hajnoczi
The
console_select()function does not check thatactive_consoleis non-NULL before dereferencing it. When invoked with qemu -nodefaults it is possible to hit this case.This patch checks that
active_consoleis non-NULL before stashing away the old console dimensions inconsole_select().
Looks sane to me, simliar tests exist in other places.
cheers,
Gerd
Am 20.09.2010 15:11, schrieb Stefan Hajnoczi:
Quoted 19 lines
The
console_select()function does not check thatactive_consoleis non-NULL before dereferencing it. When invoked with qemu -nodefaults it is possible to hit this case.This patch checks that
active_consoleis non-NULL before stashing away the old console dimensions inconsole_select().Signed-off-by Stefan Hajnoczi <[email protected]>---
console.c| 6 ++++--1 files changed, 4 insertions(+), 2 deletions(-)console.c +0
-0@@ -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
-2return ; - 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
Blue Swirl
AppliedThanks, applied.
Quoted 34 lines · Stefan Hajnoczi
The
console_select()function does not check thatactive_consoleis non-NULL before dereferencing it. When invoked with qemu -nodefaults it is possible to hit this case.This patch checks that
active_consoleis non-NULL before stashing away the old console dimensions inconsole_select().Signed-off-by Stefan Hajnoczi <[email protected]>---
console.c | 6 ++++--1 files changed, 4 insertions(+), 2 deletions(-)console.c +4
-3@@ -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