diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-04-25 09:59:55 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-04-25 09:59:55 +0000 |
commit | 45d042ed961a04b641eac99584b045de27388708 (patch) | |
tree | 670437cf48e6a91a3efadbd6b07681738b60ec9d /llvm/lib/ObjectYAML/ObjectYAML.cpp | |
parent | 4b7d3c48317c064e6a7048f7eee14677f1fddcc5 (diff) | |
download | bcm5719-llvm-45d042ed961a04b641eac99584b045de27388708.tar.gz bcm5719-llvm-45d042ed961a04b641eac99584b045de27388708.zip |
[yaml2obj] - Don't crash on invalid inputs.
yaml2obj might crash on invalid input when unable to parse the YAML.
Recently a crash with a very similar nature was fixed for an empty files.
This patch revisits the fix and does it in yaml::Input instead.
It seems to be more correct way to handle such situation.
With that crash for invalid inputs is also fixed now.
Differential revision: https://reviews.llvm.org/D61059
llvm-svn: 359178
Diffstat (limited to 'llvm/lib/ObjectYAML/ObjectYAML.cpp')
-rw-r--r-- | llvm/lib/ObjectYAML/ObjectYAML.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/llvm/lib/ObjectYAML/ObjectYAML.cpp b/llvm/lib/ObjectYAML/ObjectYAML.cpp index daadde98365..7f636f4eaba 100644 --- a/llvm/lib/ObjectYAML/ObjectYAML.cpp +++ b/llvm/lib/ObjectYAML/ObjectYAML.cpp @@ -32,6 +32,7 @@ void MappingTraits<YamlObjectFile>::mapping(IO &IO, MappingTraits<MachOYAML::UniversalBinary>::mapping(IO, *ObjectFile.FatMachO); } else { + Input &In = (Input &)IO; if (IO.mapTag("!ELF")) { ObjectFile.Elf.reset(new ELFYAML::Object()); MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf); @@ -51,15 +52,12 @@ void MappingTraits<YamlObjectFile>::mapping(IO &IO, } else if (IO.mapTag("!WASM")) { ObjectFile.Wasm.reset(new WasmYAML::Object()); MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm); - } else { - Input &In = (Input &)IO; - std::string Tag = In.getCurrentNode()->getRawTag(); - if (Tag.empty()) + } else if (const Node *N = In.getCurrentNode()) { + if (N->getRawTag().empty()) IO.setError("YAML Object File missing document type tag!"); else - IO.setError( - Twine("YAML Object File unsupported document type tag '") + - Twine(Tag) + Twine("'!")); + IO.setError("YAML Object File unsupported document type tag '" + + N->getRawTag() + "'!"); } } } |