nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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