nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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