This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Fix use of freed memory.
ClosedPublic

Authored by grimar on Dec 20 2016, 7:26 AM.

Details

Summary

It was revealed by D27831.

If we have linkerscript that includes another one that sets OUTPUT for example:

  1. RUN: echo "INCLUDE \"foo.script\"" > %t.script
  2. RUN: echo "OUTPUT(\"%t.out\")" > %T/foo.script

then we do:

void ScriptParser::readInclude() {
...
  std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
  tokenize(MB->getMemBufferRef());
  OwningMBs.push_back(std::move(MB));
}

void ScriptParser::readOutput() {
...
    Config->OutputFile = unquote(Tok);
...
}

Problem is that OwningMBs are destroyed after script parser do its job.
So all Toks are dead and Config->OutputFile points to destroyed data.

Patch suggests to save all included scripts into using string Saver.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 82107.Dec 20 2016, 7:26 AM
grimar retitled this revision from to [ELF] - Fix use of freed memory..
grimar updated this object.
grimar added reviewers: rafael, ruiu.
grimar added subscribers: davide, llvm-commits, grimar, evgeny777.
emaste added a subscriber: emaste.Dec 20 2016, 7:35 AM
ruiu accepted this revision.Dec 20 2016, 3:44 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Dec 20 2016, 3:44 PM
This revision was automatically updated to reflect the committed changes.