public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Correct odd loop in ecoff lookup_line
Date: Mon, 6 Mar 2023 14:01:47 +1030	[thread overview]
Message-ID: <ZAVeo2/RNgqKm+AA@squeak.grove.modra.org> (raw)

I can't see why this really odd looking loop was written the way it
was in commit a877f5917f90, but it can result in a buffer overrun.

	* ecofflink.c (lookup_line): Don't swap in pdr at pdr_end.

diff --git a/bfd/ecofflink.c b/bfd/ecofflink.c
index 422ce57f430..00f1e3da404 100644
--- a/bfd/ecofflink.c
+++ b/bfd/ecofflink.c
@@ -2093,7 +2093,7 @@ lookup_line (bfd *abfd,
 	     because we iterate over every FDR rather than just ones
 	     with a base address less than or equal to 'offset'.  */
 	  bfd_signed_vma dist = -1, min_dist = -1;
-	  char *pdr_hold;
+	  char *pdr_hold = NULL;
 	  char *pdr_end;
 
 	  fdr_ptr = tab[i].fdr;
@@ -2101,17 +2101,14 @@ lookup_line (bfd *abfd,
 	  pdr_ptr = ((char *) debug_info->external_pdr
 		     + fdr_ptr->ipdFirst * external_pdr_size);
 	  pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;
-	  (*debug_swap->swap_pdr_in) (abfd, pdr_ptr, &pdr);
 	  /* Find PDR that is closest to OFFSET.  If pdr.prof is set,
 	     the procedure entry-point *may* be 0x10 below pdr.adr.  We
 	     simply pretend that pdr.prof *implies* a lower entry-point.
 	     This is safe because it just means that may identify 4 NOPs
 	     in front of the function as belonging to the function.  */
-	  for (pdr_hold = NULL;
-	       pdr_ptr < pdr_end;
-	       (pdr_ptr += external_pdr_size,
-		(*debug_swap->swap_pdr_in) (abfd, pdr_ptr, &pdr)))
+	  for (; pdr_ptr < pdr_end; pdr_ptr += external_pdr_size)
 	    {
+	      (*debug_swap->swap_pdr_in) (abfd, pdr_ptr, &pdr);
 	      if (offset >= (pdr.adr - 0x10 * pdr.prof))
 		{
 		  dist = offset - (pdr.adr - 0x10 * pdr.prof);

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-03-06  3:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZAVeo2/RNgqKm+AA@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).