From: Alan Modra <amodra@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] mmo.c leak in mmo_make_section
Date: Wed, 17 Aug 2022 07:08:52 +0000 (GMT) [thread overview]
Message-ID: <20220817070852.2028C38582B5@sourceware.org> (raw)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7a1bc25b9d2c3f066000d07b5254d20367b6da0f
commit 7a1bc25b9d2c3f066000d07b5254d20367b6da0f
Author: Alan Modra <amodra@gmail.com>
Date: Wed Aug 17 15:48:21 2022 +0930
mmo.c leak in mmo_make_section
* mmo.c (mmo_make_section): Alloc name using bfd_alloc. Use
bfd_error_no_memory.
(mmo_decide_section): Check for NULL return from mmo_make_section.
Diff:
---
bfd/mmo.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/bfd/mmo.c b/bfd/mmo.c
index 1c901ae5c20..30af28c8bdc 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -463,17 +463,15 @@ mmo_make_section (bfd *abfd, const char *secname)
if (sec == NULL)
{
- char *newsecname = strdup (secname);
+ size_t len = strlen (secname) + 1;
+ char *newsecname = bfd_alloc (abfd, len);
if (newsecname == NULL)
{
- _bfd_error_handler
- /* xgettext:c-format */
- (_("%pB: no core to allocate section name %s"),
- abfd, secname);
- bfd_set_error (bfd_error_system_call);
+ bfd_set_error (bfd_error_no_memory);
return NULL;
}
+ memcpy (newsecname, secname, len);
sec = bfd_make_section (abfd, newsecname);
}
@@ -727,7 +725,7 @@ mmo_decide_section (bfd *abfd, bfd_vma vma)
sprintf (sec_name, ".MMIX.sec.%d", abfd->tdata.mmo_data->sec_no++);
sec = mmo_make_section (abfd, sec_name);
- if (!sec->user_set_vma && !bfd_set_section_vma (sec, vma))
+ if (!sec || (!sec->user_set_vma && !bfd_set_section_vma (sec, vma)))
return NULL;
if (!bfd_set_section_flags (sec, (bfd_section_flags (sec)
reply other threads:[~2022-08-17 7:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220817070852.2028C38582B5@sourceware.org \
--to=amodra@sourceware.org \
--cc=bfd-cvs@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).