aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-08-08 16:53:48 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-09-24 14:06:32 +0100
commit09dd90b0230aae35acdb505f4cdcd577d200d32c (patch)
treed26fa9ab90e2031a3069b2f489125467d2785840
parentdde074f887ff9f45dec8155aefcba7054c98f5b6 (diff)
downloadbinutils-09dd90b0230aae35acdb505f4cdcd577d200d32c.zip
binutils-09dd90b0230aae35acdb505f4cdcd577d200d32c.tar.gz
binutils-09dd90b0230aae35acdb505f4cdcd577d200d32c.tar.bz2
libctf: allow ctf_type_lname of a null pointer.
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.
-rw-r--r--libctf/ChangeLog5
-rw-r--r--libctf/ctf-types.c3
2 files changed, 7 insertions, 1 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index d3db890..e7ae44d 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,8 @@
+2019-08-08 Nick Alcock <nick.alcock@oracle.com>
+
+ * ctf-types.c (ctf_type_name): Don't strlen a potentially-
+ null pointer.
+
2019-08-07 Nick Alcock <nick.alcock@oracle.com>
* ctf-impl.h (ctf_file_t) <ctf_add_processing>: New.
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index 6e67762..ec221d7 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);