libctf, types: ints, floats and typedefs with no name are invalid

Report them as such, rather than letting ctf_decl_sprintf wrongly
conclude that the printing of zero characters means we are out of
memory.

libctf/
	* ctf-types.c (ctf_type_aname): Return ECTF_CORRUPT if
	ints, floats or typedefs have no name.  Fix comment typo.
This commit is contained in:
Nick Alcock
2020-06-02 20:49:14 +01:00
parent 502e838ed9
commit 96e3ec2966
2 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
* ctf-types.c (ctf_type_aname): Return ECTF_CORRUPT if
ints, floats or typedefs have no name. Fix comment typo.
2020-07-22 Nick Alcock <nick.alcock@oracle.com> 2020-07-22 Nick Alcock <nick.alcock@oracle.com>
* ctf-create.c (ctf_add_slice): Support slices of any kind that * ctf-create.c (ctf_add_slice): Support slices of any kind that

View File

@ -316,7 +316,7 @@ ctf_id_t ctf_lookup_by_rawhash (ctf_file_t *fp, ctf_names_t *np, const char *nam
return id; return id;
} }
/* Lookup the given type ID and return its name as a new dynamcally-allocated /* Lookup the given type ID and return its name as a new dynamically-allocated
string. */ string. */
char * char *
@ -379,6 +379,15 @@ ctf_type_aname (ctf_file_t *fp, ctf_id_t type)
case CTF_K_INTEGER: case CTF_K_INTEGER:
case CTF_K_FLOAT: case CTF_K_FLOAT:
case CTF_K_TYPEDEF: case CTF_K_TYPEDEF:
/* Integers, floats, and typedefs must always be named types. */
if (name[0] == '\0')
{
ctf_set_errno (fp, ECTF_CORRUPT);
ctf_decl_fini (&cd);
return NULL;
}
ctf_decl_sprintf (&cd, "%s", name); ctf_decl_sprintf (&cd, "%s", name);
break; break;
case CTF_K_POINTER: case CTF_K_POINTER: