Blame SOURCES/0449-io-gzio-Bail-if-gzio-tl-td-is-NULL.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Daniel Axtens <dja@axtens.net>
80913e
Date: Wed, 13 Jan 2021 20:59:09 +1100
80913e
Subject: [PATCH] io/gzio: Bail if gzio->tl/td is NULL
80913e
80913e
This is an ugly fix that doesn't address why gzio->tl comes to be NULL.
80913e
However, it seems to be sufficient to patch up a bunch of NULL derefs.
80913e
80913e
It would be good to revisit this in future and see if we can have
80913e
a cleaner solution that addresses some of the causes of the unexpected
80913e
NULL pointers.
80913e
80913e
Signed-off-by: Daniel Axtens <dja@axtens.net>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/io/gzio.c | 20 ++++++++++++++++++++
80913e
 1 file changed, 20 insertions(+)
80913e
80913e
diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c
b32e65
index 2ecf076dd..6e9b9c936 100644
80913e
--- a/grub-core/io/gzio.c
80913e
+++ b/grub-core/io/gzio.c
80913e
@@ -669,6 +669,13 @@ inflate_codes_in_window (grub_gzio_t gzio)
80913e
     {
80913e
       if (! gzio->code_state)
80913e
 	{
80913e
+
80913e
+	  if (gzio->tl == NULL)
80913e
+	    {
80913e
+	      grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->tl");
80913e
+	      return 1;
80913e
+	    }
80913e
+
80913e
 	  NEEDBITS ((unsigned) gzio->bl);
80913e
 	  if ((e = (t = gzio->tl + ((unsigned) b & ml))->e) > 16)
80913e
 	    do
80913e
@@ -707,6 +714,12 @@ inflate_codes_in_window (grub_gzio_t gzio)
80913e
 	      n = t->v.n + ((unsigned) b & mask_bits[e]);
80913e
 	      DUMPBITS (e);
80913e
 
80913e
+	      if (gzio->td == NULL)
80913e
+		{
80913e
+		  grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->td");
80913e
+		  return 1;
80913e
+		}
80913e
+
80913e
 	      /* decode distance of block to copy */
80913e
 	      NEEDBITS ((unsigned) gzio->bd);
80913e
 	      if ((e = (t = gzio->td + ((unsigned) b & md))->e) > 16)
80913e
@@ -917,6 +930,13 @@ init_dynamic_block (grub_gzio_t gzio)
80913e
   n = nl + nd;
80913e
   m = mask_bits[gzio->bl];
80913e
   i = l = 0;
80913e
+
80913e
+  if (gzio->tl == NULL)
80913e
+    {
80913e
+      grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->tl");
80913e
+      return;
80913e
+    }
80913e
+
80913e
   while ((unsigned) i < n)
80913e
     {
80913e
       NEEDBITS ((unsigned) gzio->bl);