From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR26741, benign use after free in riscv_parse_prefixed_ext
Date: Mon, 4 Jan 2021 11:10:47 +1030 [thread overview]
Message-ID: <20210104004047.GI5129@bubble.grove.modra.org> (raw)
ISO/IEC 9899:1999 C standard "J.2 Undefined behavior" says the
following is undefined behaviour:
"The value of a pointer that refers to space deallocated by a call to
the free or realloc function is used (7.20.3)."
PR 26741
* elfxx-riscv.c (riscv_parse_prefixed_ext): Free subset after
calculating subset version length.
diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
index 9d7f606995..101e27f820 100644
--- a/bfd/elfxx-riscv.c
+++ b/bfd/elfxx-riscv.c
@@ -1572,8 +1572,8 @@ riscv_parse_prefixed_ext (riscv_parse_subset_t *rps,
riscv_parse_add_subset (rps, subset,
major_version,
minor_version, FALSE);
- free (subset);
p += end_of_version - subset;
+ free (subset);
if (*p != '\0' && *p != '_')
{
--
Alan Modra
Australia Development Lab, IBM
next reply other threads:[~2021-01-04 0:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-04 0:40 Alan Modra [this message]
2021-01-22 3:10 ` Nelson Chu
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=20210104004047.GI5129@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).