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