0114-io-gzio-Bail-if-gzio-tl-td-is-NULL.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. From 3334a5e6c86f10e715cca3bf66ce0fc2f164b61b Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Wed, 13 Jan 2021 20:59:09 +1100
  4. Subject: [PATCH] io/gzio: Bail if gzio->tl/td is NULL
  5. This is an ugly fix that doesn't address why gzio->tl comes to be NULL.
  6. However, it seems to be sufficient to patch up a bunch of NULL derefs.
  7. It would be good to revisit this in future and see if we can have
  8. a cleaner solution that addresses some of the causes of the unexpected
  9. NULL pointers.
  10. Signed-off-by: Daniel Axtens <dja@axtens.net>
  11. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  12. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  13. ---
  14. grub-core/io/gzio.c | 20 ++++++++++++++++++++
  15. 1 file changed, 20 insertions(+)
  16. diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c
  17. index 43d98a7..4a8eaea 100644
  18. --- a/grub-core/io/gzio.c
  19. +++ b/grub-core/io/gzio.c
  20. @@ -669,6 +669,13 @@ inflate_codes_in_window (grub_gzio_t gzio)
  21. {
  22. if (! gzio->code_state)
  23. {
  24. +
  25. + if (gzio->tl == NULL)
  26. + {
  27. + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->tl");
  28. + return 1;
  29. + }
  30. +
  31. NEEDBITS ((unsigned) gzio->bl);
  32. if ((e = (t = gzio->tl + ((unsigned) b & ml))->e) > 16)
  33. do
  34. @@ -707,6 +714,12 @@ inflate_codes_in_window (grub_gzio_t gzio)
  35. n = t->v.n + ((unsigned) b & mask_bits[e]);
  36. DUMPBITS (e);
  37. + if (gzio->td == NULL)
  38. + {
  39. + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->td");
  40. + return 1;
  41. + }
  42. +
  43. /* decode distance of block to copy */
  44. NEEDBITS ((unsigned) gzio->bd);
  45. if ((e = (t = gzio->td + ((unsigned) b & md))->e) > 16)
  46. @@ -917,6 +930,13 @@ init_dynamic_block (grub_gzio_t gzio)
  47. n = nl + nd;
  48. m = mask_bits[gzio->bl];
  49. i = l = 0;
  50. +
  51. + if (gzio->tl == NULL)
  52. + {
  53. + grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "NULL gzio->tl");
  54. + return;
  55. + }
  56. +
  57. while ((unsigned) i < n)
  58. {
  59. NEEDBITS ((unsigned) gzio->bl);
  60. --
  61. 2.14.2