Fix Potential Use-After-Free of Temporary Twine

Twine is non-owning and the lifetime of the result ends at the semicolon
here unless it is consumed into an owning abstraction. Convert to
a std::string first then insert that into the buffer here.

Not a big deal since this is along a catastrophic error path.
This commit is contained in:
Robert Widmann
2021-07-21 14:58:12 -07:00
parent 382809ad08
commit cc246db38f

View File

@@ -1938,8 +1938,8 @@ OverlayFileContents::load(std::unique_ptr<llvm::MemoryBuffer> input,
return error;
if (contents.version > 1) {
auto message = Twine("key 'version' has invalid value: ") + Twine(contents.version);
errorMessages.push_back(message.str());
std::string message = (Twine("key 'version' has invalid value: ") + Twine(contents.version)).str();
errorMessages.emplace_back(std::move(message));
return make_error_code(std::errc::result_out_of_range);
}