libctf: create: don't add forwards if the type added already exists
authorNick Alcock <nick.alcock@oracle.com>
Mon, 21 Oct 2019 10:33:19 +0000 (11:33 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 26 Jun 2020 14:56:39 +0000 (15:56 +0100)
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 (ctf_add_forward): Don't add forwards to
types that already exist.

libctf/ChangeLog
libctf/ctf-create.c

index 056cb7b929d374533dd9ee9d1b1f0b38b2cc1364..7868d0b5a9e0cc5c228958513092b2823be57367 100644 (file)
@@ -1,3 +1,8 @@
+2020-06-26  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-create.c (ctf_add_forward): Don't add forwards to
+       types that already exist.
+
 2020-06-26  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-open.c (init_types): Only intern root-visible types.
index e8e80287cb3cc7dd8bd345017522245c818797d3..c24a246c16410aff66ce9375004aa293062de5f4 100644 (file)
@@ -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);