From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 2028C38582B5; Wed, 17 Aug 2022 07:08:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2028C38582B5 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] mmo.c leak in mmo_make_section X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 2bda15d73cb1d6c4e3db402682d4c11a94d96b7b X-Git-Newrev: 7a1bc25b9d2c3f066000d07b5254d20367b6da0f Message-Id: <20220817070852.2028C38582B5@sourceware.org> Date: Wed, 17 Aug 2022 07:08:52 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2022 07:08:52 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7a1bc25b9d2c= 3f066000d07b5254d20367b6da0f commit 7a1bc25b9d2c3f066000d07b5254d20367b6da0f Author: Alan Modra Date: Wed Aug 17 15:48:21 2022 +0930 mmo.c leak in mmo_make_section =20 * 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_secti= on. 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) =20 if (sec =3D=3D NULL) { - char *newsecname =3D strdup (secname); + size_t len =3D strlen (secname) + 1; + char *newsecname =3D bfd_alloc (abfd, len); =20 if (newsecname =3D=3D 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 =3D bfd_make_section (abfd, newsecname); } =20 @@ -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 =3D mmo_make_section (abfd, sec_name); =20 - 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; =20 if (!bfd_set_section_flags (sec, (bfd_section_flags (sec)