Bug 11572 - Segmentation fault in name demangler on 64-bit
Summary: Segmentation fault in name demangler on 64-bit
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1
: P2 normal
Target Milestone: 7.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-05 20:37 UTC by James Lyon
Modified: 2010-09-10 22:42 UTC (History)
1 user (show)

See Also:
Host: Ubuntu 10.04
Target:
Build:
Last reconfirmed:


Attachments
GDB session with backtrace and dumps of relevant data structures (1.70 KB, text/plain)
2010-05-05 20:38 UTC, James Lyon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Lyon 2010-05-05 20:37:11 UTC
I get a segmentation fault when trying to load my program. The crash happens in
the function d_find_pack during demangling. The name which ultimately causes
this error is:

_ZN3Psi7VariantIIcPKcEE5visitIIRZN11VariantTest9TestVisit11test_methodEvEUlS2_E0_RZNS6_11test_methodEvEUlcE1_RZNS6_11test_methodEvEUlNS_4NoneEE_EEENS_13VariantDetail19SelectVisitorResultIIDpT_EE4typeEDpOSG_

I'll attach a GDB session tracking the error. This appears to be related to
64-bit, since the s_unary_num.num field is set to zero in this instance which on
a 32-bit system would cause the s_binary.right field to be NULL, but that does
not happen here. In any case I don't think the s_binary member should be
accessed since the type is DEMANGLE_COMPONENT_LAMBDA, so I've fixed it by adding
a case to d_find_pack to check for it:

@@ -3467,7 +3467,8 @@
 
     case DEMANGLE_COMPONENT_PACK_EXPANSION:
       return NULL;

+    case DEMANGLE_COMPONENT_LAMBDA:
     case DEMANGLE_COMPONENT_NAME:
     case DEMANGLE_COMPONENT_OPERATOR:
     case DEMANGLE_COMPONENT_BUILTIN_TYPE:

I don't know if this is really the right place to fix it though.
Comment 1 James Lyon 2010-05-05 20:38:29 UTC
Created attachment 4770 [details]
GDB session with backtrace and dumps of relevant data structures
Comment 2 Tom Tromey 2010-05-12 20:26:57 UTC
The best way to get a review of this patch is to submit it to GCC,
where this code is canonically maintained.
Also you might consider adding a regression test to the demangler test suite.
Comment 3 Tom Tromey 2010-09-10 22:42:31 UTC
I checked in the fix and test case.