Skip to contentSkip to conversation

hw/display/exynos4210_fimd: Fix potential NULL pointer dereference

PATCH Superseded AlexChen 3 participants 5 messages Nov 2, 2020 Arm Samsung Exynos

lore
Share & tools
lore

AlexChen

author
#0 lore raw

PATCH v2 1/1 hw/display/exynos4210_fimd: Fix potential NULL pointer dereference

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.

---
 hw/display/exynos4210_fimd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/display/exynos4210_fimd.c +3 -1
index 4c16e1f5a0..34a960a976 100644
@@ -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);
 
Signature · 1 line
2.19.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 1 line · AlexChen

In exynos4210_fimd_update(), the pointer s is dereferinced before

Typo dereferinced -> dereferenced.

Quoted 2 lines

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

Quoted 6 lines
---
 hw/display/exynos4210_fimd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
author
#2 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 1 line · AlexChen

In exynos4210_fimd_update(), the pointer s is dereferinced before

Typo dereferinced -> dereferenced.

Quoted 2 lines

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

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
---
 hw/display/exynos4210_fimd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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

Thanks,
Alex

author
#3 lore raw

PATCH v3 1/1 hw/display/exynos4210_fimd: Fix potential NULL pointer dereference

In reply to Philippe Mathieu-Daudé

In exynos4210_fimd_update(), the pointer 's' is dereferenced before checking it is valid, which may lead to NULL pointer dereference. So move the assignment to global_width after checking 's' is valid.

---
 hw/display/exynos4210_fimd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/display/exynos4210_fimd.c +3 -1
index 4c16e1f5a0..34a960a976 100644
@@ -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);
 
Signature · 1 line
2.19.1
#4 lore raw
Quoted 11 lines · AlexChen

In exynos4210_fimd_update(), the pointer 's' is dereferenced before checking it is valid, which may lead to NULL pointer dereference. So move the assignment to global_width after checking 's' is valid.

---
 hw/display/exynos4210_fimd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied to target-arm.next, thanks.

-- PMM