Fix allocate_filenum last dir/file checks

Message ID YUgarQOPPnTFMfqh@squeak.grove.modra.org
State New
Headers show
Series
  • Fix allocate_filenum last dir/file checks
Related show

Commit Message

H.J. Lu via Binutils Sept. 20, 2021, 5:22 a.m.
I noticed when looking at the aarch64-linux kernel gas segfault, that
the last_used/last_used_dir_len shortcut was never firing.  dir_len
includes the final path separator.

	* dwarf2dbg.c (allocate_filenum) Correct use of last_used_dir_len.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index e2abe19c88a..c6e439aa862 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -730,9 +730,9 @@  allocate_filenum (const char * pathname)
 	}
       else
 	{
-	  if (filename_ncmp (pathname, dirname, last_used_dir_len) == 0
-	      && IS_DIR_SEPARATOR (pathname [last_used_dir_len])
-	      && filename_cmp (pathname + last_used_dir_len + 1,
+	  if (filename_ncmp (pathname, dirname, last_used_dir_len - 1) == 0
+	      && IS_DIR_SEPARATOR (pathname [last_used_dir_len - 1])
+	      && filename_cmp (pathname + last_used_dir_len,
 			       files[last_used].filename) == 0)
 	    return last_used;
 	}