From 841b6ab990116462ce48922cd9703fc99fbbc450 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Mon, 16 Mar 2020 15:03:30 -0700 Subject: [PATCH] fb: Fix possible NULL pointer de-reference ftpr assignment is being done before checking fb->fonts pointer. Just changing assignment position. Fixes 23299 [1] Signed-off-by: Flavio Ceolin --- subsys/fb/cfb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/fb/cfb.c b/subsys/fb/cfb.c index 50b9cfa936..8c973e63f1 100644 --- a/subsys/fb/cfb.c +++ b/subsys/fb/cfb.c @@ -106,12 +106,14 @@ static u8_t draw_char_vtmono(const struct char_framebuffer *fb, int cfb_print(struct device *dev, char *str, u16_t x, u16_t y) { const struct char_framebuffer *fb = &char_fb; - const struct cfb_font *fptr = &(fb->fonts[fb->font_idx]); + const struct cfb_font *fptr; if (!fb->fonts || !fb->buf) { return -1; } + fptr = &(fb->fonts[fb->font_idx]); + if (fptr->height % 8) { LOG_ERR("Wrong font size"); return -1;