From 45d042ed961a04b641eac99584b045de27388708 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Thu, 25 Apr 2019 09:59:55 +0000 Subject: [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 --- llvm/lib/Support/YAMLTraits.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Support/YAMLTraits.cpp') diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp index e7932fe4239..183da5b3900 100644 --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/lib/Support/YAMLTraits.cpp @@ -113,6 +113,11 @@ const Node *Input::getCurrentNode() const { } bool Input::mapTag(StringRef Tag, bool Default) { + // CurrentNode can be null if setCurrentDocument() was unable to + // parse the document because it was invalid or empty. + if (!CurrentNode) + return false; + std::string foundTag = CurrentNode->_node->getVerbatimTag(); if (foundTag.empty()) { // If no tag found and 'Tag' is the default, say it was found. -- cgit v1.2.3