Reported by: Alperen Erkan <[email protected]>
---
 i386/i386at/immc.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/i386/i386at/immc.c b/i386/i386at/immc.c
index 6e4d9661..c9d6cf66 100644
--- a/i386/i386at/immc.c
+++ b/i386/i386at/immc.c
@@ -132,6 +132,11 @@ immc_putc(char c)
 #define IMMC_MAXCOLS 160
 #define IMMC_MAXROWS  60
 
+/* These unlikely minima ensure that the code functions without
+   breaking limits for assertions and so on. */
+#define IMMC_MINCOLS   1
+#define IMMC_MINROWS   2
+
 static uint8_t  immc_matrix[IMMC_MAXCOLS * IMMC_MAXROWS];
 static uint8_t *immc_fb_vaddr;
 
@@ -169,6 +174,7 @@ immc_l2_table[NPTES] __aligned(PAGE_SIZE);
 static pt_entry_t
 immc_l1_tables[IMMC_FB_NUM_PAGETABLES][NPTES] __aligned(PAGE_SIZE);
 
+/* A successful initialisation results in a non-NULL fb_vaddr. */
 static void
 immc_enable_fb(const uint64_t paddr,
               const uint32_t pitch,
@@ -177,10 +183,13 @@ immc_enable_fb(const uint64_t paddr,
               const uint8_t  bpp)
 {
   uint64_t fb_size = ((uint64_t)pitch * (uint64_t)height);
-
   const uint64_t paddr_end = round_page (paddr + fb_size);
   uint64_t paddr_map = trunc_page (paddr);
 
+  /* Check for bogus input parameters. */
+  if (pitch == 0 || paddr_end < paddr_map)
+    return;
+
   memset (immc_l3_table, 0, sizeof (immc_l3_table));
   memset (immc_l2_table, 0, sizeof (immc_l2_table));
 
@@ -236,7 +245,8 @@ immc_enable_fb(const uint64_t paddr,
          if (immc_cols > IMMC_MAXCOLS)
            immc_cols = IMMC_MAXCOLS;
 
-         if (fb_disp_set_dimensions (immc_cols, immc_rows, immc_matrix))
+         if (immc_cols >= IMMC_MINCOLS && immc_rows >= IMMC_MINROWS
+             && fb_disp_set_dimensions (immc_cols, immc_rows, immc_matrix))
            immc_fb_vaddr = IMMC_FB_VADDR;
        }
 
-- 
2.47.3


Reply via email to