When copying types from one CTF container to another, ensure that we

encode 0-length (i.e. "") structure and union member names as offset 0.
This ensures that we don't confuse other parts of the CTF code which
expect this encoding.

This resolves a Dtrace error resolving members of anonymous structs/unions
within the (struct mbuf) type which some users were seeing after r366908.

While here, update the code in ctf_add_generic() to encode 0-length type
names as offset 0.

Reviewed by:	markj
MFC after:	2 weeks
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D27246
This commit is contained in:
Jonathan T. Looney 2020-11-20 17:26:02 +00:00
parent d84134ba1c
commit 96fbe51956

View File

@ -615,7 +615,7 @@ ctf_add_generic(ctf_file_t *fp, uint_t flag, const char *name, ctf_dtdef_t **rp)
if ((dtd = ctf_alloc(sizeof (ctf_dtdef_t))) == NULL)
return (ctf_set_errno(fp, EAGAIN));
if (name != NULL && (s = ctf_strdup(name)) == NULL) {
if (name != NULL && *name != '\0' && (s = ctf_strdup(name)) == NULL) {
ctf_free(dtd, sizeof (ctf_dtdef_t));
return (ctf_set_errno(fp, EAGAIN));
}
@ -1217,7 +1217,7 @@ membadd(const char *name, ctf_id_t type, ulong_t offset, void *arg)
if ((dmd = ctf_alloc(sizeof (ctf_dmdef_t))) == NULL)
return (ctf_set_errno(ctb->ctb_file, EAGAIN));
if (name != NULL && (s = ctf_strdup(name)) == NULL) {
if (name != NULL && *name != '\0' && (s = ctf_strdup(name)) == NULL) {
ctf_free(dmd, sizeof (ctf_dmdef_t));
return (ctf_set_errno(ctb->ctb_file, EAGAIN));
}