aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-08-17 15:48:21 +0930
committerAlan Modra <amodra@gmail.com>2022-08-17 16:35:57 +0930
commit7a1bc25b9d2c3f066000d07b5254d20367b6da0f (patch)
treefcc1acd2e56adc4cc8546895463ac70b6a1ce41c /bfd
parent2bda15d73cb1d6c4e3db402682d4c11a94d96b7b (diff)
downloadgdb-7a1bc25b9d2c3f066000d07b5254d20367b6da0f.zip
gdb-7a1bc25b9d2c3f066000d07b5254d20367b6da0f.tar.gz
gdb-7a1bc25b9d2c3f066000d07b5254d20367b6da0f.tar.bz2
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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/mmo.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/bfd/mmo.c b/bfd/mmo.c
index 1c901ae..30af28c 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)