hw/display/exynos4210_fimd: Fix potential NULL pointer dereference
PATCH 1/1 hw/display/exynos4210_fimd: Fix potential NULL pointer dereference
In exynos4210_fimd_update(), the pointer s is dereferenced before being check if it is valid, which may lead to NULL pointer dereference. So move the assignment to global_width after checking that the s is valid
--- hw/display/exynos4210_fimd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/exynos4210_fimd.c +1 -1
@@ -1275,12 +1275,12 @@ static void exynos4210_fimd_update(void *opaque)bool blend = false;uint8_t *host_fb_addr;bool is_dirty = false; -const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;if (!s || !s->console || !s->enabled ||surface_bits_per_pixel (qemu_console_surface (s->console)) ==0 ) {return ; } +const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;exynos4210_update_resolution (s); surface =qemu_console_surface (s->console);
Signature · 1 line
2.19.1
Quoted 18 lines · AlexChen
In
exynos4210_fimd_update(), the pointer s is dereferenced before being check if it is valid, which may lead to NULL pointer dereference. So move the assignment toglobal_widthafter checking that the s is validReported-by Euler Robot <[email protected]>Signed-off-by Alex Chen <[email protected]>--- hw/display/exynos4210_fimd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/display/exynos4210_fimd.c +0
-0@@ -1275,12 +1275,12 @@ static void exynos4210_fimd_update(void *opaque)bool blend = false;uint8_t *host_fb_addr;
hw/display/exynos4210_fimd.c static void exynos4210_fimd_update(void *opaque) · line 1285
Quoted 10 lines
hw/display/exynos4210_fimd.c +1
-1bool is_dirty = false; -const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;if (!s || !s->console || !s->enabled ||surface_bits_per_pixel (qemu_console_surface (s->console)) ==0 ) {return ; } +const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;exynos4210_update_resolution (s); surface =qemu_console_surface (s->console);
Yep, this is a bug, but QEMU's coding style doesn't permit variable declarations in the middle of functions. You need to split the declaration (which stays where it is) and the initialization (which can moved down below the !s test.
thanks
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 21 lines · AlexChen
In
exynos4210_fimd_update(), the pointer s is dereferenced before being check if it is valid, which may lead to NULL pointer dereference. So move the assignment toglobal_widthafter checking that the s is validReported-by Euler Robot <[email protected]>Signed-off-by Alex Chen <[email protected]>--- hw/display/exynos4210_fimd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/display/exynos4210_fimd.c +0
-1@@ -1275,12 +1275,12 @@ static void exynos4210_fimd_update(void *opaque)bool blend = false;uint8_t *host_fb_addr;bool is_dirty = false; -const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;
Quoted 13 lines
hw/display/exynos4210_fimd.c static void exynos4210_fimd_update(void *opaque) · line 1285
Quoted 7 lines
hw/display/exynos4210_fimd.c +1
-0if (!s || !s->console || !s->enabled ||surface_bits_per_pixel (qemu_console_surface (s->console)) ==0 ) {return ; } +const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;exynos4210_update_resolution (s); surface =qemu_console_surface (s->console);Yep, this is a bug, but QEMU's coding style doesn't permit variable declarations in the middle of functions. You need to split the declaration (which stays where it is) and the initialization (which can moved down below the !s test.
Thans for your review. I have also considered this modification to be incompatible with the QEMU's coding style. But the type of global_width is const int which cannot be assigned once they are defined.
Could we define the global_width as int, such as this modification:
hw/display/exynos4210_fimd.c +3 -1
@@ -1275,12 +1275,14 @@ static void exynos4210_fimd_update(void *opaque)bool blend = false;uint8_t *host_fb_addr;bool is_dirty = false; -const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ; +int global_width;if (!s || !s->console || !s->enabled ||surface_bits_per_pixel (qemu_console_surface (s->console)) ==0 ) {return ; } + + global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;exynos4210_update_resolution (s); surface =qemu_console_surface (s->console);
Quoted 51 lines · AlexChen
Quoted 22 lines · Peter Maydell
Quoted 21 lines · AlexChen
In
exynos4210_fimd_update(), the pointer s is dereferenced before being check if it is valid, which may lead to NULL pointer dereference. So move the assignment toglobal_widthafter checking that the s is validReported-by Euler Robot <[email protected]>Signed-off-by Alex Chen <[email protected]>--- hw/display/exynos4210_fimd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/display/exynos4210_fimd.c +0
-1@@ -1275,12 +1275,12 @@ static void exynos4210_fimd_update(void *opaque)bool blend = false;uint8_t *host_fb_addr;bool is_dirty = false; -const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;Quoted 13 lines
hw/display/exynos4210_fimd.c static void exynos4210_fimd_update(void *opaque) · line 1287
Quoted 7 lines
hw/display/exynos4210_fimd.c +1
-0if (!s || !s->console || !s->enabled ||surface_bits_per_pixel (qemu_console_surface (s->console)) ==0 ) {return ; } +const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;exynos4210_update_resolution (s); surface =qemu_console_surface (s->console);Yep, this is a bug, but QEMU's coding style doesn't permit variable declarations in the middle of functions. You need to split the declaration (which stays where it is) and the initialization (which can moved down below the !s test.
Thans for your review. I have also considered this modification to be incompatible with the QEMU's coding style. But the type of
global_widthis const int which cannot be assigned once they are defined.
Could we define theglobal_widthas int, such as this modification:hw/display/exynos4210_fimd.c +0
-1@@ -1275,12 +1275,14 @@ static void exynos4210_fimd_update(void *opaque)bool blend = false;uint8_t *host_fb_addr;bool is_dirty = false; -const int global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;
hw/display/exynos4210_fimd.c static void exynos4210_fimd_update(void *opaque) · line 1287
Quoted 10 lines
hw/display/exynos4210_fimd.c +3
-0+int global_width;if (!s || !s->console || !s->enabled ||surface_bits_per_pixel (qemu_console_surface (s->console)) ==0 ) {return ; } + + global_width = (s->vidtcon[2 ] &FIMD_VIDTCON2_SIZE_MASK ) +1 ;exynos4210_update_resolution (s); surface =qemu_console_surface (s->console);
Yes, I think that would be fine.
thanks
-- PMM