This is an archive of the discontinued LLVM Phabricator instance.

llvm-undname: Fix more crashes and asserts on invalid inputs
ClosedPublic

Authored by thakis on Apr 5 2019, 7:32 PM.

Details

Summary

For functions whose callers don't check that enough input is present,
add checks at the start of the function that enough input is there and
set Error otherwise.

For functions that return AST objects, return nullptr instead of
incomplete AST objects with nullptr fields if an error occurred during
the function.

Introduce a new function demangleDeclarator() for the sequence
demangleFullyQualifiedSymbolName(); demangleEncodedSymbol() and
use it in the two places that had this sequence. Let this new function
check that ConversionOperatorIdentifiers have a valid TargetType.

Some of the bad inputs found by oss-fuzz, others by inspection.

Diff Detail

Event Timeline

thakis created this revision.Apr 5 2019, 7:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2019, 7:32 PM
thakis updated this revision to Diff 194047.Apr 6 2019, 6:37 PM

Add test coverage for each modification -- removing each green block now makes some test fail. Found another bug this way, fix that too. Found a few tests I had added that aren't reachable, removed those.

zturner added inline comments.Apr 8 2019, 11:55 AM
llvm/lib/Demangle/MicrosoftDemangle.cpp
722–724

How about

if (Error)
  return nullptr;

assert(Symbol);
Symbol->Name = QN;
1962

s/guarantess/guarantees/

That said, I would just change this to:

// isMemberPointer() only returns true if there is at least one character after the qualifiers.
assert(!MangledName.empty());
thakis updated this revision to Diff 194190.Apr 8 2019, 12:14 PM
thakis marked 4 inline comments as done.

Address comments (but don't add the assert()s because they're implied by the line following the assert in both cases).

llvm/lib/Demangle/MicrosoftDemangle.cpp
722–724

That's fine too. I just moved this code around though, see line 732 on the lhs.

1962

Thanks, that's better.

zturner accepted this revision.Apr 8 2019, 12:44 PM
This revision is now accepted and ready to land.Apr 8 2019, 12:44 PM
This revision was automatically updated to reflect the committed changes.