From cefe7e1142c082816dc3da743e4be45a2fdfe723 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 llvm-svn: 313746 --- llvm/include/llvm/Support/YAMLTraits.h | 4 ++-- llvm/test/Object/yaml2obj-invalid.yaml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 llvm/test/Object/yaml2obj-invalid.yaml diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h index 71fdf47..5f6f049 100644 --- a/llvm/include/llvm/Support/YAMLTraits.h +++ b/llvm/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/llvm/test/Object/yaml2obj-invalid.yaml b/llvm/test/Object/yaml2obj-invalid.yaml new file mode 100644 index 0000000..d1f4fa2 --- /dev/null +++ b/llvm/test/Object/yaml2obj-invalid.yaml @@ -0,0 +1,2 @@ +# RUN: not yaml2obj %s 2>&1 | FileCheck %s +# CHECK: Unknown document type! -- 2.7.4