]> git.proxmox.com Git - grub2.git/commitdiff
io/gzio: Zero gzio->tl/td in init_dynamic_block() if huft_build() fails
authorDaniel Axtens <dja@axtens.net>
Thu, 21 Jan 2021 01:22:28 +0000 (12:22 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:18 +0000 (15:54 +0100)
If huft_build() fails, gzio->tl or gzio->td could contain pointers that
are no longer valid. Zero them out.

This prevents a double free when grub_gzio_close() comes through and
attempts to free them again.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/io/gzio.c

index 19adebeede6ef28e0ce229a732b229d300e88fac..aea86a0a9a92daa23f20583903985cb23c35fc9e 100644 (file)
@@ -1010,6 +1010,7 @@ init_dynamic_block (grub_gzio_t gzio)
   gzio->bl = lbits;
   if (huft_build (ll, nl, 257, cplens, cplext, &gzio->tl, &gzio->bl) != 0)
     {
+      gzio->tl = 0;
       grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
                  "failed in building a Huffman code table");
       return;
@@ -1019,6 +1020,7 @@ init_dynamic_block (grub_gzio_t gzio)
     {
       huft_free (gzio->tl);
       gzio->tl = 0;
+      gzio->td = 0;
       grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
                  "failed in building a Huffman code table");
       return;