nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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