Commit Graph

11 Commits

Author SHA1 Message Date
Fred Riss e3ae0756a1 Fix use-after-free in Demangler caused by Words[] not saved across nested demangle calls
DemangleInitRAII saves and restores NumWords but not the Words[] array
itself. When a nested demangleSymbol/demangleType call processes
identifiers, it overwrites Words[] entries with StringRefs pointing
into its own Text buffer. After ~DemangleInitRAII restores the outer
NumWords, those entries still reference the inner (now-destroyed)
buffer. The outer demangling then hits a word substitution and reads
freed memory through the stale StringRef.

In practice this is triggered by MetadataReader::demangle(): the
symbolic reference resolver calls buildContextManglingForSymbol which
calls dem.demangleSymbol() on the same Demangler. The inner symbol's
identifiers overwrite Words[] with pointers into the
ParentContextDescriptorRef's temporary string. When the resolver
returns and the PCCDR is destroyed, the outer demangleType accesses
dangling Words[] entries via word substitution identifiers.

The fix adds Words[] to DemangleInitRAII's saved/restored state.

rdar://172223904

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 10:34:00 -07:00
Dmitrii Galimzianov df9ecd9a4c [Demangler] Stable parent identifier in OpaqueReturnTypeParent
`OpaqueReturnTypeParent` node now references the parent with a mangled parent name, rather than a parent pointer. This makes trees obtained from different demanglers (or calls to `Demangler::demangleSymbol`) for the same symbol equal.
2024-09-18 01:14:38 +02:00
Adrian Prantl 4b1532cddc Rename swift::Demangle::archetypeName() to swift::Demangle::genericParameterName(). 2019-03-01 08:02:28 -08:00
Adrian Prantl b36c646914 Allow for passing a custom Archetype naming schema to the demangler.
LLDB would like to substitute the original Archetype names from the
source code when demangling symbols instead of the confusing generic
'A', 'B', ...

<rdar://problem/48259889>
2019-02-28 14:01:38 -08:00
Erik Eckstein 39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Davide Italiano e4d9813b40 [Demangler] Adjust the implementation of isObjCSymbol().
Pointed out by Jordan.
2018-09-18 13:48:51 -07:00
Davide Italiano dbe5ee77b8 [Demangler] Implement isObjCSymbol().
This function can be queried to find out whether the passed
mangled name is an Objective-C symbol. This will be used
in the debugger to replace an hardcoded check that would
break if the mangling prefix changed.

<rdar://problem/44467875>
2018-09-18 11:32:16 -07:00
Erik Eckstein 5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Erik Eckstein 437d4da38d Demangling: Remove StringRef-versions of demangling functions from demangle_wrappers because they are now available in Demangle itself.
This is just refactoring. NFC.
2017-02-24 15:19:18 -08:00
Michael Gottesman e678f4979b [gardening] Add swift license headers to all files in ./unittests/Basic/*. 2017-02-09 22:02:42 -08:00
Michael Gottesman af61ed85a4 [gardening] Standardize ./unittests/Basic so that all tests have the Test.cpp suffix. 2017-02-09 21:50:57 -08:00