[yaml2obj] - Don't crash on invalid document.
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 20 Sep 2017 09:57:11 +0000 (09:57 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 20 Sep 2017 09:57:11 +0000 (09:57 +0000)
Previously jaml2obj would segfault on empty document.
(without yaml description).
Patch fixes the issue.

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

llvm-svn: 313746

llvm/include/llvm/Support/YAMLTraits.h
llvm/test/Object/yaml2obj-invalid.yaml [new file with mode: 0644]

index 71fdf47..5f6f049 100644 (file)
@@ -1418,8 +1418,8 @@ inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
                                Input &>::type
 operator>>(Input &yin, T &docMap) {
   EmptyContext Ctx;
-  yin.setCurrentDocument();
-  yamlize(yin, docMap, true, Ctx);
+  if (yin.setCurrentDocument())
+    yamlize(yin, docMap, true, Ctx);
   return yin;
 }
 
diff --git a/llvm/test/Object/yaml2obj-invalid.yaml b/llvm/test/Object/yaml2obj-invalid.yaml
new file mode 100644 (file)
index 0000000..d1f4fa2
--- /dev/null
@@ -0,0 +1,2 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+# CHECK: Unknown document type!