From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Re: vms buffer overflows and large memory allocation
Date: Wed, 26 Feb 2020 04:56:00 -0000 [thread overview]
Message-ID: <20200226045650.GG5750@bubble.grove.modra.org> (raw)
In-Reply-To: <20200224020650.GD5570@bubble.grove.modra.org>
git commit c893ce360a changed buffer management, in the process
introducing a bug on an error return path. Obviously committed in too
much of a hurry.
* vms-lib.c (vms_lib_read_index): Release correct buffer.
diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c
index 87f865864c..29e213f8c3 100644
--- a/bfd/vms-lib.c
+++ b/bfd/vms-lib.c
@@ -416,6 +416,7 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel)
unsigned int vbn;
ufile_ptr filesize;
size_t amt;
+ struct carsym *csbuf;
struct carsym_mem csm;
/* Read index desription. */
@@ -447,7 +448,7 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel)
csm.max = csm.limit;
if (_bfd_mul_overflow (csm.max, sizeof (struct carsym), &amt))
return NULL;
- csm.idx = bfd_alloc (abfd, amt);
+ csm.idx = csbuf = bfd_alloc (abfd, amt);
if (csm.idx == NULL)
return NULL;
@@ -455,12 +456,12 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel)
vbn = bfd_getl32 (idd.vbn);
if (vbn != 0 && !vms_traverse_index (abfd, vbn, &csm))
{
- if (csm.realloced && csm.idx != NULL)
+ if (csm.realloced)
free (csm.idx);
/* Note: in case of error, we can free what was allocated on the
BFD's objalloc. */
- bfd_release (abfd, csm.idx);
+ bfd_release (abfd, csbuf);
return NULL;
}
@@ -468,7 +469,6 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel)
{
/* There are more entries than the first estimate. Allocate on
the BFD's objalloc. */
- struct carsym *csbuf;
csbuf = bfd_alloc (abfd, csm.nbr * sizeof (struct carsym));
if (csbuf == NULL)
return NULL;
--
Alan Modra
Australia Development Lab, IBM
prev parent reply other threads:[~2020-02-26 4:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 2:07 Alan Modra
2020-02-24 2:55 ` Alan Modra
2020-02-26 4:56 ` Alan Modra [this message]
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=20200226045650.GG5750@bubble.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@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).