This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH v4 31/35] libctf: allow ctf_type_lname of a null pointer.
- From: Nick Alcock <nick dot alcock at oracle dot com>
- To: binutils at sourceware dot org
- Cc: Nick Alcock <nick dot alcock at oracle dot com>
- Date: Tue, 24 Sep 2019 14:51:27 +0100
- Subject: [PATCH v4 31/35] libctf: allow ctf_type_lname of a null pointer.
- References: <20190924135131.441906-1-nick.alcock@oracle.com>
The code was meant to handle this, but accidentally dereferenced the
null pointer before checking it for nullity.
libctf/
* ctf-types.c (ctf_type_name): Don't strlen a potentially-
null pointer.
---
libctf/ctf-types.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index 6e677622343..ec221d73494 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -438,11 +438,12 @@ ssize_t
ctf_type_lname (ctf_file_t *fp, ctf_id_t type, char *buf, size_t len)
{
char *str = ctf_type_aname (fp, type);
- size_t slen = strlen (str);
+ size_t slen;
if (str == NULL)
return CTF_ERR; /* errno is set for us */
+ slen = strlen (str);
snprintf (buf, len, "%s", str);
free (str);
--
2.23.0.239.g28aa4420fd