[patch] Fix use after free in BitcodeReader.cpp error path

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Oct 30 09:53:01 PDT 2013


CCing Tobias because he wrote the code being patched and Chris because
he wrote most of the file and its asserts.

I am trying to create an ObjectFile wrapper for bitcode files for use
in llvm-nm, llvm-ar and lld. One issue is that ObjectFile uses
error_code. The error handling at the bitcode libraries is a somewhat
confusing mix. Some errors are returned via a std::string, some via a
fixed list of "const char*" and some just use asserts.

One particular case tries to use const char* but ends up accessing
freed memory. What this patch does is convert that case to use a fatal
error. Is that OK? I am assuming so since it is fairly easy to hit the
asserts with a broken bitcode file (and they should probably be
converted to a fatal error so we handle them correctly in release
builds).

If non fatal error is desired for this library, we probably have to
find a way to extend error_code to hold a std::string so that we can
use it to report "Unknown attribute kind (38)" instead of just
"Unknown attribute kind".

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: text/x-patch
Size: 2401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131030/cf804de6/attachment.bin>


More information about the llvm-commits mailing list