Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFAv2] Fix buffer overflow regression due to minsym malloc-ed instead of obstack-ed.
Date: Mon, 25 Mar 2019 15:31:00 -0000	[thread overview]
Message-ID: <87h8brj7ie.fsf@tromey.com> (raw)
In-Reply-To: <20190324091856.2529-1-philippe.waroquiers@skynet.be> (Philippe	Waroquiers's message of "Sun, 24 Mar 2019 10:18:56 +0100")

>>>>> "Philippe" == Philippe Waroquiers <philippe.waroquiers@skynet.be> writes:

Philippe> Before this commit, the array of 'struct minimal_symbol'
Philippe> contained a last element that was a "null symbol".  The comment in
Philippe> minimal_symbol_reader::install was:

Sorry about this.

Philippe> Note that a bunch of comments in minimal_symbol_reader::install
Philippe> are still referring to allocations being done in obstack.  These
Philippe> comments seem obsolete.  I have not fixed them, as I have not
Philippe> understood what they are explaining (e.g. related to language
Philippe> auto, demangling, etc : I have not seen where all this is done).

The comment about language_auto is mildly incorrect, and I think
probably has been for quite some time.

There are some other incorrect comments in there.  I'll send a patch.

Philippe> +  int n_after_msymbol = minsym.objfile->per_bfd->minimal_symbol_count
Philippe> +    - (msymbol - minsym.objfile->per_bfd->msymbols.get ())
Philippe> +    - 1;

What do you think of the appended instead?
The idea is to make the last element more explicit.

Tom

diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index b95e9ef6e8b..03743e3062b 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1480,11 +1480,10 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
 CORE_ADDR
 minimal_symbol_upper_bound (struct bound_minimal_symbol minsym)
 {
-  int i;
   short section;
   struct obj_section *obj_section;
   CORE_ADDR result;
-  struct minimal_symbol *msymbol;
+  struct minimal_symbol *iter, *msymbol;
 
   gdb_assert (minsym.minsym != NULL);
 
@@ -1499,21 +1498,24 @@ minimal_symbol_upper_bound (struct bound_minimal_symbol minsym)
      other sections, to find the next symbol in this section with a
      different address.  */
 
+  struct minimal_symbol *last
+    = (minsym.objfile->per_bfd->msymbols.get ()
+       + minsym.objfile->per_bfd->minimal_symbol_count);
   msymbol = minsym.minsym;
   section = MSYMBOL_SECTION (msymbol);
-  for (i = 1; MSYMBOL_LINKAGE_NAME (msymbol + i) != NULL; i++)
+  for (iter = msymbol + 1; iter < last; ++iter)
     {
-      if ((MSYMBOL_VALUE_RAW_ADDRESS (msymbol + i)
+      if ((MSYMBOL_VALUE_RAW_ADDRESS (iter)
 	   != MSYMBOL_VALUE_RAW_ADDRESS (msymbol))
-	  && MSYMBOL_SECTION (msymbol + i) == section)
+	  && MSYMBOL_SECTION (iter) == section)
 	break;
     }
 
   obj_section = MSYMBOL_OBJ_SECTION (minsym.objfile, minsym.minsym);
-  if (MSYMBOL_LINKAGE_NAME (msymbol + i) != NULL
-      && (MSYMBOL_VALUE_ADDRESS (minsym.objfile, msymbol + i)
+  if (iter < last
+      && (MSYMBOL_VALUE_ADDRESS (minsym.objfile, iter)
 	  < obj_section_endaddr (obj_section)))
-    result = MSYMBOL_VALUE_ADDRESS (minsym.objfile, msymbol + i);
+    result = MSYMBOL_VALUE_ADDRESS (minsym.objfile, iter);
   else
     /* We got the start address from the last msymbol in the objfile.
        So the end address is the end of the section.  */


  reply	other threads:[~2019-03-25 15:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-24  9:19 Philippe Waroquiers
2019-03-25 15:31 ` Tom Tromey [this message]
2019-03-25 19:54   ` Philippe Waroquiers
2019-03-26 18:46     ` Simon Marchi
2019-03-26 19:20       ` Tom Tromey

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=87h8brj7ie.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=philippe.waroquiers@skynet.be \
    /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