Skip to content

Fix an OOB read in the demangler #31793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/swift/Demangling/Demangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,7 @@ class Demangler : public NodeFactory {
NodePointer demangleValueWitness();

NodePointer demangleTypeMangling();
NodePointer demangleSymbolicReference(unsigned char rawKind,
const void *at);
NodePointer demangleSymbolicReference(unsigned char rawKind);

bool demangleBoundGenerics(Vector<NodePointer> &TypeListList,
NodePointer &RetroactiveConformances);
Expand Down
10 changes: 6 additions & 4 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,14 @@ NodePointer Demangler::demangleTypeMangling() {
return TypeMangling;
}

NodePointer Demangler::demangleSymbolicReference(unsigned char rawKind,
const void *at) {
NodePointer Demangler::demangleSymbolicReference(unsigned char rawKind) {
// The symbolic reference is a 4-byte machine integer encoded in the following
// four bytes.
if (Pos + 4 > Text.size())
return nullptr;
const void *at = Text.data() + Pos;
int32_t value;
memcpy(&value, Text.data() + Pos, 4);
memcpy(&value, at, 4);
Pos += 4;

// Map the encoded kind to a specific kind and directness.
Expand Down Expand Up @@ -734,7 +736,7 @@ NodePointer Demangler::demangleOperator() {
goto recur;
case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
case 9: case 0xA: case 0xB: case 0xC:
return demangleSymbolicReference((unsigned char)c, Text.data() + Pos);
return demangleSymbolicReference((unsigned char)c);
case 'A': return demangleMultiSubstitutions();
case 'B': return demangleBuiltinType();
case 'C': return demangleAnyGenericType(Node::Kind::Class);
Expand Down