diff options
| author | George Rimar <grimar@accesssoftek.com> | 2017-09-21 08:25:59 +0000 | 
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2017-09-21 08:25:59 +0000 | 
| commit | 3674fb6f2c061250f4f40b7f261a16b0595a3b6a (patch) | |
| tree | 2240d2b0ad53d9141496d8e57fb507dd7b99834d | |
| parent | 5536a01ad24973c93fd39f227e814f98f8bf86d7 (diff) | |
| download | bcm5719-llvm-3674fb6f2c061250f4f40b7f261a16b0595a3b6a.tar.gz bcm5719-llvm-3674fb6f2c061250f4f40b7f261a16b0595a3b6a.zip  | |
[yaml2obj] - Don't crash on one more invalid document.
This fixes one more crash I faced.
Testcase contains minimal reduced case.
Differential revision: https://reviews.llvm.org/D38082
llvm-svn: 313868
| -rw-r--r-- | llvm/lib/Support/YAMLTraits.cpp | 14 | ||||
| -rw-r--r-- | llvm/test/Object/yaml2obj-invalid.yaml | 4 | 
2 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp index 65eda246a7f..75a2224a772 100644 --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/lib/Support/YAMLTraits.cpp @@ -374,18 +374,22 @@ std::unique_ptr<Input::HNode> Input::createHNodes(Node *N) {      auto mapHNode = llvm::make_unique<MapHNode>(N);      for (KeyValueNode &KVN : *Map) {        Node *KeyNode = KVN.getKey(); -      ScalarNode *KeyScalar = dyn_cast<ScalarNode>(KeyNode); -      if (!KeyScalar) { -        setError(KeyNode, "Map key must be a scalar"); +      ScalarNode *Key = dyn_cast<ScalarNode>(KeyNode); +      Node *Value = KVN.getValue(); +      if (!Key || !Value) { +        if (!Key) +          setError(KeyNode, "Map key must be a scalar"); +        if (!Value) +          setError(KeyNode, "Map value must not be empty");          break;        }        StringStorage.clear(); -      StringRef KeyStr = KeyScalar->getValue(StringStorage); +      StringRef KeyStr = Key->getValue(StringStorage);        if (!StringStorage.empty()) {          // Copy string to permanent storage          KeyStr = StringStorage.str().copy(StringAllocator);        } -      auto ValueHNode = this->createHNodes(KVN.getValue()); +      auto ValueHNode = this->createHNodes(Value);        if (EC)          break;        mapHNode->Mapping[KeyStr] = std::move(ValueHNode); diff --git a/llvm/test/Object/yaml2obj-invalid.yaml b/llvm/test/Object/yaml2obj-invalid.yaml new file mode 100644 index 00000000000..fba4ad81407 --- /dev/null +++ b/llvm/test/Object/yaml2obj-invalid.yaml @@ -0,0 +1,4 @@ +AAA: | BBB + +# RUN: not yaml2obj %s 2>&1 | FileCheck %s +# CHECK: Map value must not be empty  | 

