public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* More _bfd_ecoff_locate_line sanity checks
@ 2023-03-06  3:32 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-03-06  3:32 UTC (permalink / raw)
  To: binutils

	* ecofflink.c (mk_fdrtab): Discard fdr with negative cpd.
	(lookup_line): Sanity check fdr cbLineOffset and cbLine.
	Sanity check pdr cbLineOffset.

diff --git a/bfd/ecofflink.c b/bfd/ecofflink.c
index 00f1e3da404..bba25929f2c 100644
--- a/bfd/ecofflink.c
+++ b/bfd/ecofflink.c
@@ -1742,6 +1742,7 @@ mk_fdrtab (bfd *abfd,
       /* Sanity check fdr procedure descriptor pointer.  */
       long ipdMax = debug_info->symbolic_header.ipdMax;
       if (fdr_ptr->ipdFirst >= ipdMax
+	  || fdr_ptr->cpd < 0
 	  || fdr_ptr->cpd > ipdMax - fdr_ptr->ipdFirst)
 	fdr_ptr->cpd = 0;
       /* Skip FDRs that have no PDRs.  */
@@ -2146,12 +2147,20 @@ lookup_line (bfd *abfd,
 	 are stored in a very funky format, which I won't try to
 	 describe.  The search is bounded by the end of the FDRs line
 	 number entries.  */
-      line_end = debug_info->line + fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
+      line_ptr = line_end = debug_info->line;
+      if (fdr_ptr->cbLineOffset < debug_info->symbolic_header.cbLine
+	  && fdr_ptr->cbLine <= (debug_info->symbolic_header.cbLine
+				 - fdr_ptr->cbLineOffset)
+	  && pdr.cbLineOffset <= (debug_info->symbolic_header.cbLine
+				  - fdr_ptr->cbLineOffset))
+	{
+	  line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
+	  line_ptr += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
+	}
 
       /* Make offset relative to procedure entry.  */
       offset -= pdr.adr - 0x10 * pdr.prof;
       lineno = pdr.lnLow;
-      line_ptr = debug_info->line + fdr_ptr->cbLineOffset + pdr.cbLineOffset;
       while (line_ptr < line_end)
 	{
 	  int delta;

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-06  3:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06  3:32 More _bfd_ecoff_locate_line sanity checks Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).