gdb: Guard against NULL dereference in dwarf2_init_integer_type
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 6 Nov 2018 19:55:21 +0000 (19:55 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 7 Nov 2018 12:58:56 +0000 (12:58 +0000)
commit35ee2dc2e4de8b1ae73f420d5db3375f92300b70
tree0e3bf62a6485e3d8d9345ed6d3a404919ab43076
parent42d4c301c45df41d1c724b7b86f8683a875c010a
gdb: Guard against NULL dereference in dwarf2_init_integer_type

In this commit:

    commit eb77c9df9f6d2f7aa644a170280fe31ce080f887
    Date:   Thu Oct 18 14:04:27 2018 +0100

        gdb: Handle ICC's unexpected void return type

A potential dereference of a NULL pointer was introduced if a
DW_TAG_base_type is missing a DW_AT_name attribute.

I have taken this opportunity to fix a slight confusion that existed
in the test also added in the above commit, the test had two C
variables, declared like this:

    int var_a = 5;

    void *var_ptr = &var_a;

However, the fake DWARF in the test script declared them like this:

    void var_a = 5;

    void *var_ptr = &var_a;

This wasn't a problem as the test never uses 'var_a' directly, this
only exists so 'var_ptr' can be initialised.  However, it seemed worth
fixing.

I've also added a test for a DW_TAG_base_type with a missing
DW_AT_name, as clearly there's not test currently that covers this
(the original patch tested cleanly).  I can confirm that the new test
causes GDB to crash before this patch, and passes with this patch.

gdb/ChangeLog:

* dwarf2read.c (dwarf2_init_integer_type): Check for name being
NULL before dereferencing it.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/void-type.exp: Rename types, and make var_a an 'int'.
* gdb.dwarf2/missing-type-name.exp: New file.
gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.dwarf2/missing-type-name.exp [new file with mode: 0644]
gdb/testsuite/gdb.dwarf2/void-type.exp