[RFA] Initialize py_type_printers in ext_lang_type_printers

Message ID 20180516174302.29092-1-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey May 16, 2018, 5:43 p.m. UTC
  When running gdb in the build directory without passing
--data-directory, I noticed I could provoke a crash by:

    $ ./gdb -nx ./gdb
    (gdb) ptype/o struct dwarf2_per_objfile

... and then trying to "q" out at the pagination prompt.

valgrind complained about an uninitialized use of py_type_printers.
Initializing this member fixes the bug.

I believe this bug can occur even when the gdb Python libraries are
available, for example if get_type_recognizers fails.

Tested by hand on x86-64 Fedora 26.  No test case because it seemed
difficult to guarantee failures.

gdb/ChangeLog
2018-05-16  Tom Tromey  <tom@tromey.com>

	* extension.h (struct ext_lang_type_printers) <py_type_printers>:
	Initialize.
---
 gdb/ChangeLog   | 5 +++++
 gdb/extension.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
  

Comments

Phil Muldoon May 17, 2018, 10:32 a.m. UTC | #1
On 16/05/18 18:43, Tom Tromey wrote:
> When running gdb in the build directory without passing
> --data-directory, I noticed I could provoke a crash by:
> 
>     $ ./gdb -nx ./gdb
>     (gdb) ptype/o struct dwarf2_per_objfile
> 
> ... and then trying to "q" out at the pagination prompt.
> 
> valgrind complained about an uninitialized use of py_type_printers.
> Initializing this member fixes the bug.
> 
> I believe this bug can occur even when the gdb Python libraries are
> available, for example if get_type_recognizers fails.
> 
> Tested by hand on x86-64 Fedora 26.  No test case because it seemed
> difficult to guarantee failures.
> 
> gdb/ChangeLog
> 2018-05-16  Tom Tromey  <tom@tromey.com>
> 
> 	* extension.h (struct ext_lang_type_printers) <py_type_printers>:
> 	Initialize.
> ---
>  gdb/ChangeLog   | 5 +++++
>  gdb/extension.h | 2 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/extension.h b/gdb/extension.h
> index abde5e54e1..0c8c4ee934 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -152,7 +152,7 @@ struct ext_lang_type_printers
>    DISABLE_COPY_AND_ASSIGN (ext_lang_type_printers);
>  
>    /* Type-printers from Python.  */
> -  void *py_type_printers;
> +  void *py_type_printers = nullptr;
>  };
>  
>  /* The return code for some API calls.  */
> 

LGTM

Cheers

Phil
  
Pedro Alves May 17, 2018, 1:25 p.m. UTC | #2
On 05/17/2018 11:32 AM, Phil Muldoon wrote:
> On 16/05/18 18:43, Tom Tromey wrote:

> LGTM

Thanks Phil.  LGTM too.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/extension.h b/gdb/extension.h
index abde5e54e1..0c8c4ee934 100644
--- a/gdb/extension.h
+++ b/gdb/extension.h
@@ -152,7 +152,7 @@  struct ext_lang_type_printers
   DISABLE_COPY_AND_ASSIGN (ext_lang_type_printers);
 
   /* Type-printers from Python.  */
-  void *py_type_printers;
+  void *py_type_printers = nullptr;
 };
 
 /* The return code for some API calls.  */