|
|
c4e390 |
From 73b56b15b1951e1cbff50fa86ac55faabf5a4176 Mon Sep 17 00:00:00 2001
|
|
|
c4e390 |
From: Peter Jones <pjones@redhat.com>
|
|
|
c4e390 |
Date: Sat, 4 Jul 2020 12:25:09 -0400
|
|
|
c4e390 |
Subject: [PATCH 304/336] iso9660: Don't leak memory on realloc() failures
|
|
|
c4e390 |
|
|
|
c4e390 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
c4e390 |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
c4e390 |
Upstream-commit-id: f2bd30b2fe7
|
|
|
c4e390 |
---
|
|
|
c4e390 |
grub-core/fs/iso9660.c | 24 ++++++++++++++++++++----
|
|
|
c4e390 |
1 file changed, 20 insertions(+), 4 deletions(-)
|
|
|
c4e390 |
|
|
|
c4e390 |
diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c
|
|
|
c4e390 |
index d6dc55b5803..f1611c5e311 100644
|
|
|
c4e390 |
--- a/grub-core/fs/iso9660.c
|
|
|
c4e390 |
+++ b/grub-core/fs/iso9660.c
|
|
|
c4e390 |
@@ -533,14 +533,20 @@ add_part (struct iterate_dir_ctx *ctx,
|
|
|
c4e390 |
{
|
|
|
c4e390 |
grub_size_t size = ctx->symlink ? grub_strlen (ctx->symlink) : 0;
|
|
|
c4e390 |
grub_size_t sz;
|
|
|
c4e390 |
+ char *new;
|
|
|
c4e390 |
|
|
|
c4e390 |
if (grub_add (size, len2, &sz) ||
|
|
|
c4e390 |
grub_add (sz, 1, &sz))
|
|
|
c4e390 |
return;
|
|
|
c4e390 |
|
|
|
c4e390 |
- ctx->symlink = grub_realloc (ctx->symlink, sz);
|
|
|
c4e390 |
- if (! ctx->symlink)
|
|
|
c4e390 |
- return;
|
|
|
c4e390 |
+ new = grub_realloc (ctx->symlink, sz);
|
|
|
c4e390 |
+ if (!new)
|
|
|
c4e390 |
+ {
|
|
|
c4e390 |
+ grub_free (ctx->symlink);
|
|
|
c4e390 |
+ ctx->symlink = NULL;
|
|
|
c4e390 |
+ return;
|
|
|
c4e390 |
+ }
|
|
|
c4e390 |
+ ctx->symlink = new;
|
|
|
c4e390 |
|
|
|
c4e390 |
grub_memcpy (ctx->symlink + size, part, len2);
|
|
|
c4e390 |
ctx->symlink[size + len2] = 0;
|
|
|
c4e390 |
@@ -634,7 +640,12 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
|
|
|
c4e390 |
is the length. Both are part of the `Component
|
|
|
c4e390 |
Record'. */
|
|
|
c4e390 |
if (ctx->symlink && !ctx->was_continue)
|
|
|
c4e390 |
- add_part (ctx, "/", 1);
|
|
|
c4e390 |
+ {
|
|
|
c4e390 |
+ add_part (ctx, "/", 1);
|
|
|
c4e390 |
+ if (grub_errno)
|
|
|
c4e390 |
+ return grub_errno;
|
|
|
c4e390 |
+ }
|
|
|
c4e390 |
+
|
|
|
c4e390 |
add_part (ctx, (char *) &entry->data[pos + 2],
|
|
|
c4e390 |
entry->data[pos + 1]);
|
|
|
c4e390 |
ctx->was_continue = (entry->data[pos] & 1);
|
|
|
c4e390 |
@@ -653,6 +664,11 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
|
|
|
c4e390 |
add_part (ctx, "/", 1);
|
|
|
c4e390 |
break;
|
|
|
c4e390 |
}
|
|
|
c4e390 |
+
|
|
|
c4e390 |
+ /* Check if grub_realloc() failed in add_part(). */
|
|
|
c4e390 |
+ if (grub_errno)
|
|
|
c4e390 |
+ return grub_errno;
|
|
|
c4e390 |
+
|
|
|
c4e390 |
/* In pos + 1 the length of the `Component Record' is
|
|
|
c4e390 |
stored. */
|
|
|
c4e390 |
pos += entry->data[pos + 1] + 2;
|
|
|
c4e390 |
--
|
|
|
c4e390 |
2.26.2
|
|
|
c4e390 |
|