]> granicus.if.org Git - llvm/commitdiff
[yaml2obj] - Don't crash on one more invalid document.
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 21 Sep 2017 08:25:59 +0000 (08:25 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 21 Sep 2017 08:25:59 +0000 (08:25 +0000)
This fixes one more crash I faced.
Testcase contains minimal reduced case.

Differential revision: https://reviews.llvm.org/D38082

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313868 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/YAMLTraits.cpp
test/Object/yaml2obj-invalid.yaml [new file with mode: 0644]

index 65eda246a7feab1d0c1f4cc546a2fffcf93259ff..75a2224a772b1193c37acb3655588613c1a392db 100644 (file)
@@ -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/test/Object/yaml2obj-invalid.yaml b/test/Object/yaml2obj-invalid.yaml
new file mode 100644 (file)
index 0000000..fba4ad8
--- /dev/null
@@ -0,0 +1,4 @@
+AAA: | BBB
+
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+# CHECK: Map value must not be empty