Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* dwarf2_build_psymtabs should check that .debug_line exists
@ 2002-08-07 16:53 david carlton
  2002-08-13 13:50 ` Jim Blandy
  0 siblings, 1 reply; 5+ messages in thread
From: david carlton @ 2002-08-07 16:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: carlton

I was reading through dwarf2read.c when I noticed that
dwarf2_build_psymtabs() doesn't check to see if the file that you're
debugging has a .debug_line section before initializing
dwarf_line_buffer.  This is potentially unfortunate:
dwarf2_build_psymtabs() is called when dwarf2_has_info() returns 1,
but dwarf2_has_info() only checks to see if the file that you're
debugging has .debug_info and .debug_abbrev sections.

It is, of course, quite rare for a file to have .debug_info and
.debug_abbrev sections but not to have a .debug_line section; so,
obviously this isn't a serious problem.  And, even if you produce such
a file (using objcopy -R .debug_line, say), it's still pretty hard to
cause GDB to signal an error, but with some effort I did manage to do
so.  (I can submit a PR with details, if anybody wants.)  Given that
dwarf2_build_psymtabs() is careful to make sure all the other
.debug_XXX sections exist, it should certainly also check to make sure
that .debug_line exists.

By the way, I checked to see where the contents of the .debug_line
section are used; as far as I can tell, it's only used in
dwarf2read.c(dwarf_decode_line_header), and that function does have a
check in it to make sure that dwarf_line_buffer is non-NULL.  So this
fix is probably better than the other obvious fix, namely to have
dwarf2_has_info() ensure that the file has a .debug_line section.

Here's a patch; no new regressions.

2002-08-07  David Carlton  <carlton@math.stanford.edu>

	* dwarf2read.c (dwarf2_build_psymtabs): Check that
	dwarf_line_offset is nonzero before creating dwarf_line_buffer.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.64
diff -u -p -r1.64 dwarf2read.c
--- dwarf2read.c	31 Jul 2002 22:35:30 -0000	1.64
+++ dwarf2read.c	7 Aug 2002 22:55:49 -0000
@@ -1009,9 +1009,13 @@ dwarf2_build_psymtabs (struct objfile *o
   dwarf_abbrev_buffer = dwarf2_read_section (objfile,
 					     dwarf_abbrev_offset,
 					     dwarf_abbrev_size);
-  dwarf_line_buffer = dwarf2_read_section (objfile,
-					   dwarf_line_offset,
-					   dwarf_line_size);
+
+  if (dwarf_line_offset)
+    dwarf_line_buffer = dwarf2_read_section (objfile,
+					     dwarf_line_offset,
+					     dwarf_line_size);
+  else
+    dwarf_line_buffer = NULL;
 
   if (dwarf_str_offset)
     dwarf_str_buffer = dwarf2_read_section (objfile,


David Carlton
carlton@math.stanford.edu


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dwarf2_build_psymtabs should check that .debug_line exists
  2002-08-07 16:53 dwarf2_build_psymtabs should check that .debug_line exists david carlton
@ 2002-08-13 13:50 ` Jim Blandy
  2002-08-13 14:54   ` David Carlton
  0 siblings, 1 reply; 5+ messages in thread
From: Jim Blandy @ 2002-08-13 13:50 UTC (permalink / raw)
  To: david carlton; +Cc: gdb-patches


david carlton <carlton@math.stanford.edu> writes:
> I was reading through dwarf2read.c when I noticed that
> dwarf2_build_psymtabs() doesn't check to see if the file that you're
> debugging has a .debug_line section before initializing
> dwarf_line_buffer.  This is potentially unfortunate:
> dwarf2_build_psymtabs() is called when dwarf2_has_info() returns 1,
> but dwarf2_has_info() only checks to see if the file that you're
> debugging has .debug_info and .debug_abbrev sections.
> 
> It is, of course, quite rare for a file to have .debug_info and
> .debug_abbrev sections but not to have a .debug_line section; so,
> obviously this isn't a serious problem.  And, even if you produce such
> a file (using objcopy -R .debug_line, say), it's still pretty hard to
> cause GDB to signal an error, but with some effort I did manage to do
> so.  (I can submit a PR with details, if anybody wants.)  Given that
> dwarf2_build_psymtabs() is careful to make sure all the other
> .debug_XXX sections exist, it should certainly also check to make sure
> that .debug_line exists.
> 
> By the way, I checked to see where the contents of the .debug_line
> section are used; as far as I can tell, it's only used in
> dwarf2read.c(dwarf_decode_line_header), and that function does have a
> check in it to make sure that dwarf_line_buffer is non-NULL.  So this
> fix is probably better than the other obvious fix, namely to have
> dwarf2_has_info() ensure that the file has a .debug_line section.

Yes, this all makes good sense.

Well, dwarf_decode_line_header stashes pointers into the
debug_line_buffer in the struct line_header it returns.  So
dwarf_decode_lines uses dwarf_line_buffer, too.

It looks to me like read_file_scope shouldn't call dwarf_decode_macros
either when line_header is zero.  Could you add that to your patch,
and re-post it?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dwarf2_build_psymtabs should check that .debug_line exists
  2002-08-13 13:50 ` Jim Blandy
@ 2002-08-13 14:54   ` David Carlton
  2002-08-14 16:47     ` Jim Blandy
  0 siblings, 1 reply; 5+ messages in thread
From: David Carlton @ 2002-08-13 14:54 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb-patches, carlton

In article <vt24rdyze50.fsf@zenia.red-bean.com>, Jim Blandy <jimb@zenia.red-bean.com> writes:

> It looks to me like read_file_scope shouldn't call dwarf_decode_macros
> either when line_header is zero.  Could you add that to your patch,
> and re-post it?

Oh, right, good call.  Here it is; no new regressions.

David Carlton
carlton@math.stanford.edu

2002-08-13  David Carlton  <carlton@math.stanford.edu>

	* dwarf2read.c (dwarf2_build_psymtabs): Check that
	dwarf_line_offset is nonzero before creating dwarf_line_buffer.
	(read_file_scope): Check that line_header is nonzero before
	decoding macro information.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.64
diff -u -p -r1.64 dwarf2read.c
--- dwarf2read.c	31 Jul 2002 22:35:30 -0000	1.64
+++ dwarf2read.c	13 Aug 2002 21:30:02 -0000
@@ -1009,9 +1009,13 @@ dwarf2_build_psymtabs (struct objfile *o
   dwarf_abbrev_buffer = dwarf2_read_section (objfile,
 					     dwarf_abbrev_offset,
 					     dwarf_abbrev_size);
-  dwarf_line_buffer = dwarf2_read_section (objfile,
-					   dwarf_line_offset,
-					   dwarf_line_size);
+
+  if (dwarf_line_offset)
+    dwarf_line_buffer = dwarf2_read_section (objfile,
+					     dwarf_line_offset,
+					     dwarf_line_size);
+  else
+    dwarf_line_buffer = NULL;
 
   if (dwarf_str_offset)
     dwarf_str_buffer = dwarf2_read_section (objfile,
@@ -1808,7 +1812,7 @@ read_file_scope (struct die_info *die, s
      header, so we can only read it if we've read the header
      successfully.  */
   attr = dwarf_attr (die, DW_AT_macro_info);
-  if (attr)
+  if (attr && line_header)
     {
       unsigned int macro_offset = DW_UNSND (attr);
       dwarf_decode_macros (line_header, macro_offset,


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dwarf2_build_psymtabs should check that .debug_line exists
  2002-08-13 14:54   ` David Carlton
@ 2002-08-14 16:47     ` Jim Blandy
  2002-08-19 16:43       ` David Carlton
  0 siblings, 1 reply; 5+ messages in thread
From: Jim Blandy @ 2002-08-14 16:47 UTC (permalink / raw)
  To: David Carlton, Andrew Cagney; +Cc: gdb-patches


This looks good to me.

Andrew, I can't get a fresh copy of copyright.list; is David in there
yet?

David Carlton <carlton@math.stanford.edu> writes:

> In article <vt24rdyze50.fsf@zenia.red-bean.com>, Jim Blandy <jimb@zenia.red-bean.com> writes:
> 
> > It looks to me like read_file_scope shouldn't call dwarf_decode_macros
> > either when line_header is zero.  Could you add that to your patch,
> > and re-post it?
> 
> Oh, right, good call.  Here it is; no new regressions.
> 
> David Carlton
> carlton@math.stanford.edu
> 
> 2002-08-13  David Carlton  <carlton@math.stanford.edu>
> 
> 	* dwarf2read.c (dwarf2_build_psymtabs): Check that
> 	dwarf_line_offset is nonzero before creating dwarf_line_buffer.
> 	(read_file_scope): Check that line_header is nonzero before
> 	decoding macro information.
> 
> Index: dwarf2read.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/dwarf2read.c,v
> retrieving revision 1.64
> diff -u -p -r1.64 dwarf2read.c
> --- dwarf2read.c	31 Jul 2002 22:35:30 -0000	1.64
> +++ dwarf2read.c	13 Aug 2002 21:30:02 -0000
> @@ -1009,9 +1009,13 @@ dwarf2_build_psymtabs (struct objfile *o
>    dwarf_abbrev_buffer = dwarf2_read_section (objfile,
>  					     dwarf_abbrev_offset,
>  					     dwarf_abbrev_size);
> -  dwarf_line_buffer = dwarf2_read_section (objfile,
> -					   dwarf_line_offset,
> -					   dwarf_line_size);
> +
> +  if (dwarf_line_offset)
> +    dwarf_line_buffer = dwarf2_read_section (objfile,
> +					     dwarf_line_offset,
> +					     dwarf_line_size);
> +  else
> +    dwarf_line_buffer = NULL;
>  
>    if (dwarf_str_offset)
>      dwarf_str_buffer = dwarf2_read_section (objfile,
> @@ -1808,7 +1812,7 @@ read_file_scope (struct die_info *die, s
>       header, so we can only read it if we've read the header
>       successfully.  */
>    attr = dwarf_attr (die, DW_AT_macro_info);
> -  if (attr)
> +  if (attr && line_header)
>      {
>        unsigned int macro_offset = DW_UNSND (attr);
>        dwarf_decode_macros (line_header, macro_offset,


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: dwarf2_build_psymtabs should check that .debug_line exists
  2002-08-14 16:47     ` Jim Blandy
@ 2002-08-19 16:43       ` David Carlton
  0 siblings, 0 replies; 5+ messages in thread
From: David Carlton @ 2002-08-19 16:43 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb-patches, carlton

In article <vt21y91ui4n.fsf@zenia.red-bean.com>, Jim Blandy <jimb@redhat.com> writes:

> This looks good to me.

> Andrew, I can't get a fresh copy of copyright.list; is David in
> there yet?

I'm all set up now; I assume I should check in the patch?

David Carlton
carlton@math.stanford.edu


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-08-19 23:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-07 16:53 dwarf2_build_psymtabs should check that .debug_line exists david carlton
2002-08-13 13:50 ` Jim Blandy
2002-08-13 14:54   ` David Carlton
2002-08-14 16:47     ` Jim Blandy
2002-08-19 16:43       ` David Carlton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox