In case of bad DWARF4 with missing DW_AT_comp_dir there might not be a
(zero) directory name. The code already checked for that, but after
trying to call strlen on the NULL dname. If dname is NULL we don't
need the size and keep the filename relative.

       * libdw/dwarf_getsrclines.c (read_srclines): Check dname !=
       NULL before calling strlen.

Suggested-by: Tristan <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
---
 libdw/dwarf_getsrclines.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index 1d5f659b3e2e..5d48a934cfee 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -989,20 +989,18 @@ read_srclines (Dwarf *dbg,
                    const char **dirarray
                      = (const char **) &((*filesp)->info[nfiles]);
 
+                   /* Note in case of bad DWARF4 with missing
+                      DW_AT_comp_dir there might not be a (zero)
+                      directory name.  We cannot do much in this
+                      case.  Just keep the file relative.  */
                    const char *dname = dirarray[diridx];
-                   size_t dnamelen = strlen (dname);
+                   size_t dnamelen = dname != NULL ? strlen (dname) : 0;
 
                    new_file->info.name =
                      libdw_alloc (dbg, char, 1, (dnamelen + fnamelen + 2));
                    char *cp = new_file->info.name;
 
                    if (dname != NULL)
-
-                     /* This value could be NULL in case the
-                        DW_AT_comp_dir was not present.  We
-                        cannot do much in this case.  Just
-                        keep the file relative.  */
-
                      {
                        cp = stpcpy (cp, dname);
                        *cp++ = '/';
-- 
2.55.0

Reply via email to