From: George Rimar Date: Wed, 20 Sep 2017 09:57:11 +0000 (+0000) Subject: [yaml2obj] - Don't crash on invalid document. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84509c6d52c0764f46bf56807cc7bc73879b92e4;p=llvm [yaml2obj] - Don't crash on invalid document. Previously jaml2obj would segfault on empty document. (without yaml description). Patch fixes the issue. Differential revision: https://reviews.llvm.org/D38036 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313746 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/YAMLTraits.h b/include/llvm/Support/YAMLTraits.h index 71fdf47f197..5f6f0493e28 100644 --- a/include/llvm/Support/YAMLTraits.h +++ b/include/llvm/Support/YAMLTraits.h @@ -1418,8 +1418,8 @@ inline typename std::enable_if::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/test/Object/yaml2obj-invalid.yaml b/test/Object/yaml2obj-invalid.yaml new file mode 100644 index 00000000000..d1f4fa26d82 --- /dev/null +++ b/test/Object/yaml2obj-invalid.yaml @@ -0,0 +1,2 @@ +# RUN: not yaml2obj %s 2>&1 | FileCheck %s +# CHECK: Unknown document type!