diff mbox series

[V2] hw/display/exynos4210_fimd: Fix potential NULL pointer dereference

Message ID 5F9F8D88.9030102@huawei.com
State Superseded
Headers show
Series [V2] hw/display/exynos4210_fimd: Fix potential NULL pointer dereference | expand

Commit Message

Alex Chen Nov. 2, 2020, 4:39 a.m. UTC
In exynos4210_fimd_update(), the pointer s is dereferinced 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.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Alex Chen <alex.chen@huawei.com>
---
 hw/display/exynos4210_fimd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé Nov. 2, 2020, 9:16 a.m. UTC | #1
On 11/2/20 5:39 AM, AlexChen wrote:
> In exynos4210_fimd_update(), the pointer s is dereferinced before


Typo dereferinced -> dereferenced.

> 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.


Easier to read "after checking 's' is valid."

> 

> Reported-by: Euler Robot <euler.robot@huawei.com>

> Signed-off-by: Alex Chen <alex.chen@huawei.com>

> ---

>  hw/display/exynos4210_fimd.c | 4 +++-

>  1 file changed, 3 insertions(+), 1 deletion(-)


Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Alex Chen Nov. 2, 2020, 10:10 a.m. UTC | #2
On 2020/11/2 17:16, Philippe Mathieu-Daudé wrote:
> On 11/2/20 5:39 AM, AlexChen wrote:

>> In exynos4210_fimd_update(), the pointer s is dereferinced before

> 

> Typo dereferinced -> dereferenced.

> 

>> 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.

> 

> Easier to read "after checking 's' is valid."

> 

>>

>> Reported-by: Euler Robot <euler.robot@huawei.com>

>> Signed-off-by: Alex Chen <alex.chen@huawei.com>

>> ---

>>  hw/display/exynos4210_fimd.c | 4 +++-

>>  1 file changed, 3 insertions(+), 1 deletion(-)

> 

> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> 


Thanks for your review, I will fix it in my patch V3.

Thanks,
Alex
diff mbox series

Patch

diff --git a/hw/display/exynos4210_fimd.c b/hw/display/exynos4210_fimd.c
index 4c16e1f5a0..34a960a976 100644
--- a/hw/display/exynos4210_fimd.c
+++ b/hw/display/exynos4210_fimd.c
@@ -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);