dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0300-hfsplus-fix-two-more-overflows.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Peter Jones <pjones@redhat.com>
80913e
Date: Sun, 19 Jul 2020 14:43:31 -0400
80913e
Subject: [PATCH] hfsplus: fix two more overflows
80913e
80913e
Both node->size and node->namelen come from the supplied filesystem,
80913e
which may be user-supplied.  We can't trust them for the math unless we
80913e
know they don't overflow; making sure they go through calloc() first
80913e
will give us that.
80913e
80913e
Signed-off-by: Peter Jones <pjones@redhat.com>
80913e
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
80913e
Upstream-commit-id: b4915078903
80913e
---
80913e
 grub-core/fs/hfsplus.c | 11 ++++++++---
80913e
 1 file changed, 8 insertions(+), 3 deletions(-)
80913e
80913e
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
80913e
index f1cd72398ec..8b17ebba296 100644
80913e
--- a/grub-core/fs/hfsplus.c
80913e
+++ b/grub-core/fs/hfsplus.c
80913e
@@ -31,6 +31,7 @@
80913e
 #include <grub/hfs.h>
80913e
 #include <grub/charset.h>
80913e
 #include <grub/hfsplus.h>
80913e
+#include <grub/safemath.h>
80913e
 
80913e
 GRUB_MOD_LICENSE ("GPLv3+");
80913e
 
80913e
@@ -475,8 +476,12 @@ grub_hfsplus_read_symlink (grub_fshelp_node_t node)
80913e
 {
80913e
   char *symlink;
80913e
   grub_ssize_t numread;
80913e
+  grub_size_t sz = node->size;
80913e
 
80913e
-  symlink = grub_malloc (node->size + 1);
80913e
+  if (grub_add (sz, 1, &sz))
80913e
+    return NULL;
80913e
+
80913e
+  symlink = grub_malloc (sz);
80913e
   if (!symlink)
80913e
     return 0;
80913e
 
80913e
@@ -715,8 +720,8 @@ list_nodes (void *record, void *hook_arg)
80913e
   if (type == GRUB_FSHELP_UNKNOWN)
80913e
     return 0;
80913e
 
80913e
-  filename = grub_malloc (grub_be_to_cpu16 (catkey->namelen)
80913e
-			  * GRUB_MAX_UTF8_PER_UTF16 + 1);
80913e
+  filename = grub_calloc (grub_be_to_cpu16 (catkey->namelen),
80913e
+			  GRUB_MAX_UTF8_PER_UTF16 + 1);
80913e
   if (! filename)
80913e
     return 0;
80913e