[PATCH 3/5] libctf: prohibit nameless ints, floats, typedefs and forwards
Nick Alcock
nick.alcock@oracle.com
Fri Jan 29 19:29:11 GMT 2021
Now that "anonymous typedef nodes" have been extirpated, we can mandate
that things that have names in C must have names in CTF too. (Unlike
the no-forwards embarrassment, the deduplicator does nothing special
with names: types that have names in C will have the same name in CTF.
So we can assume that the CTF rules and the C rules are the same.)
include/ChangeLog
2021-01-27 Nick Alcock <nick.alcock@oracle.com>
* ctf-api.h (ECTF_NONAME): New.
(ECTF_NERR): Adjust.
libctf/ChangeLog
2021-01-27 Nick Alcock <nick.alcock@oracle.com>
* ctf-create.c (ctf_add_encoded): Add check for non-empty name.
(ctf_add_forward): Likewise.
(ctf_add_typedef): Likewise.
---
include/ctf-api.h | 5 +++--
libctf/ctf-create.c | 12 ++++++++++--
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/include/ctf-api.h b/include/ctf-api.h
index 954778a9501..6dd43aa365f 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -240,7 +240,8 @@ typedef struct ctf_snapshot_id
_CTF_ITEM (ECTF_NEXT_WRONGFP, "Iteration entity changed in mid-iterate.") \
_CTF_ITEM (ECTF_FLAGS, "CTF header contains flags unknown to libctf.") \
_CTF_ITEM (ECTF_NEEDSBFD, "This feature needs a libctf with BFD support.") \
- _CTF_ITEM (ECTF_INCOMPLETE, "Type is not a complete type.")
+ _CTF_ITEM (ECTF_INCOMPLETE, "Type is not a complete type.") \
+ _CTF_ITEM (ECTF_NONAME, "Type name must not be empty.")
#define ECTF_BASE 1000 /* Base value for libctf errnos. */
@@ -253,7 +254,7 @@ _CTF_ERRORS
#undef _CTF_FIRST
};
-#define ECTF_NERR (ECTF_INCOMPLETE - ECTF_BASE + 1) /* Count of CTF errors. */
+#define ECTF_NERR (ECTF_NONAME - ECTF_BASE + 1) /* Count of CTF errors. */
/* The CTF data model is inferred to be the caller's data model or the data
model of the given object, unless ctf_setmodel is explicitly called. */
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index cf473842846..cf12557b5d5 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -1595,6 +1595,9 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
if (ep == NULL)
return (ctf_set_errno (fp, EINVAL));
+ if (name == NULL || name[0] == '\0')
+ return (ctf_set_errno (fp, ECTF_NONAME));
+
if ((type = ctf_add_generic (fp, flag, name, kind, &dtd)) == CTF_ERR)
return CTF_ERR; /* errno is set for us. */
@@ -1961,11 +1964,13 @@ ctf_add_forward (ctf_dict_t *fp, uint32_t flag, const char *name,
if (!ctf_forwardable_kind (kind))
return (ctf_set_errno (fp, ECTF_NOTSUE));
+ if (name == NULL || name[0] == '\0')
+ return (ctf_set_errno (fp, ECTF_NONAME));
+
/* If the type is already defined or exists as a forward tag, just
return the ctf_id_t of the existing definition. */
- if (name != NULL)
- type = ctf_lookup_by_rawname (fp, kind, name);
+ type = ctf_lookup_by_rawname (fp, kind, name);
if (type)
return type;
@@ -1990,6 +1995,9 @@ ctf_add_typedef (ctf_dict_t *fp, uint32_t flag, const char *name,
if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
return (ctf_set_errno (fp, EINVAL));
+ if (name == NULL || name[0] == '\0')
+ return (ctf_set_errno (fp, ECTF_NONAME));
+
if (ref != 0 && ctf_lookup_by_id (&tmp, ref) == NULL)
return CTF_ERR; /* errno is set for us. */
--
2.30.0.252.gc27e85e57d
More information about the Binutils
mailing list