[PATCH] D38082: [yaml2obj] - Don't crash on one more invalid document.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 01:27:31 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL313868: [yaml2obj] - Don't crash on one more invalid document. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D38082?vs=116008&id=116147#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38082

Files:
  llvm/trunk/lib/Support/YAMLTraits.cpp
  llvm/trunk/test/Object/yaml2obj-invalid.yaml


Index: llvm/trunk/test/Object/yaml2obj-invalid.yaml
===================================================================
--- llvm/trunk/test/Object/yaml2obj-invalid.yaml
+++ llvm/trunk/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
Index: llvm/trunk/lib/Support/YAMLTraits.cpp
===================================================================
--- llvm/trunk/lib/Support/YAMLTraits.cpp
+++ llvm/trunk/lib/Support/YAMLTraits.cpp
@@ -374,18 +374,22 @@
     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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38082.116147.patch
Type: text/x-patch
Size: 1628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170921/38dce6be/attachment.bin>


More information about the llvm-commits mailing list