From 84509c6d52c0764f46bf56807cc7bc73879b92e4 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 20 Sep 2017 09:57:11 +0000 Subject: [PATCH] [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 --- include/llvm/Support/YAMLTraits.h | 4 ++-- test/Object/yaml2obj-invalid.yaml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 test/Object/yaml2obj-invalid.yaml 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! -- 2.50.1