This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 03/11] libctf: create: don't add forwards if the type added already exists
- From: Nick Alcock <nick dot alcock at oracle dot com>
- To: binutils at sourceware dot org
- Cc: indu dot bhagat at oracle dot com, jose dot marchesi at oracle dot com, nick dot alcock at oracle dot com
- Date: Mon, 16 Dec 2019 22:53:49 +0000
- Subject: [PATCH 03/11] libctf: create: don't add forwards if the type added already exists
- References: <20191216225357.87247-1-nick.alcock@oracle.com>
This is what ctf_add_forward is documented to do, but it's not what it
actually does: the code is quite happy to add forwards that duplicate
existing structs, etc.
This is obviously wrong and breaks both the nondeduplicating linker
and the upcoming deduplicator, as well as allowing ordinary callers of
ctf_add_type to corrupt the dictionary by just adding the same root-
visible forward more than once.
---
libctf/ctf-create.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index ff5fca353f..1099fd3a2c 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -1229,7 +1229,10 @@ ctf_add_forward (ctf_file_t *fp, uint32_t flag, const char *name,
if (name != NULL)
type = ctf_lookup_by_rawname (fp, kind, name);
- if ((type = ctf_add_generic (fp, flag, name, CTF_K_FORWARD,&dtd)) == CTF_ERR)
+ if (type)
+ return type;
+
+ if ((type = ctf_add_generic (fp, flag, name, CTF_K_FORWARD, &dtd)) == CTF_ERR)
return CTF_ERR; /* errno is set for us. */
dtd->dtd_data.ctt_info = CTF_TYPE_INFO (CTF_K_FORWARD, flag, 0);
--
2.24.1.242.gb57e918ca5