This is an archive of the discontinued LLVM Phabricator instance.

[Object, MachO] Make MachO parser significantly more robust to invalid inputs.
AbandonedPublic

Authored by samsonov on May 28 2015, 4:55 PM.

Details

Summary

In general, assume that parsing MachO command may fail: make a large
family of methods return std::error_code instead of returning MachO
commands by value.

This is a significant API change. For now I've just converted MachO
parser implementation, and will proceed with converting the callers if
this direction is approved.

This change is a part of ongoing effort to use LibFuzzer to test LLVM
object parsing/dumping machinery, see r238451 that adds
llvm-dwarfdump-fuzzer, for instance.

Diff Detail

Event Timeline

samsonov updated this revision to Diff 26754.May 28 2015, 4:55 PM
samsonov retitled this revision from to [Object, MachO] Make MachO parser significantly more robust to invalid inputs..
samsonov updated this object.
samsonov edited the test plan for this revision. (Show Details)
samsonov added reviewers: rafael, loladiro, lhames.
samsonov added a subscriber: Unknown Object (MLST).
samsonov updated this revision to Diff 26758.May 28 2015, 5:14 PM

Fix a few typos.

loladiro edited edge metadata.May 28 2015, 5:35 PM

Would it be sensible to use ErrorOr instead of adding an out parameter?

Would it be sensible to use ErrorOr instead of adding an out parameter?

std::error_code is consistent with ObjectFile interface. See include/llvm/Object/ObjectFile.h: we use std::error_code in accessors like ObjectFile::getSymbolAddress(), and only use ErrorOr in factories.

I don't really have a strong opinion either way, I just wanted to bring it up as last time I touched this file a strong preference for moving everything to ErrorOr was expressed in the review, because it's easy to ignore the std::error_code.

samsonov abandoned this revision.May 29 2015, 6:12 PM