From: Nick Alcock Date: Thu, 8 Aug 2019 15:53:48 +0000 (+0100) Subject: libctf: allow ctf_type_lname of a null pointer. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1a6ab13e712348c59c2757457b9f913a333f3c92;p=binutils-gdb.git 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. v5: fix tabdamage. libctf/ * ctf-types.c (ctf_type_name): Don't strlen a potentially- null pointer. --- diff --git a/libctf/ChangeLog b/libctf/ChangeLog index 106955385db..8f41ece32b0 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,8 @@ +2019-08-08 Nick Alcock + + * ctf-types.c (ctf_type_name): Don't strlen a potentially- + null pointer. + 2019-08-07 Nick Alcock * ctf-impl.h (ctf_file_t) : New. 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);