[PATCH] D38036: [yaml2obj] - Don't crash on invalid document.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 09:30:36 PDT 2017


LGTM

George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> grimar created this revision.
>
> Previously jaml2obj would segfault on empty document.
> (without yaml description).
> Patch fixes the issue.
>
>
> https://reviews.llvm.org/D38036
>
> Files:
>   include/llvm/Support/YAMLTraits.h
>   test/Object/yaml2obj-invalid.yaml
>
>
> Index: test/Object/yaml2obj-invalid.yaml
> ===================================================================
> --- test/Object/yaml2obj-invalid.yaml
> +++ test/Object/yaml2obj-invalid.yaml
> @@ -0,0 +1,2 @@
> +# RUN: not yaml2obj %s 2>&1 | FileCheck %s
> +# CHECK: Unknown document type!
> Index: include/llvm/Support/YAMLTraits.h
> ===================================================================
> --- include/llvm/Support/YAMLTraits.h
> +++ include/llvm/Support/YAMLTraits.h
> @@ -1418,8 +1418,8 @@
>                                 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;
>  }
>  
>
>
> Index: test/Object/yaml2obj-invalid.yaml
> ===================================================================
> --- test/Object/yaml2obj-invalid.yaml
> +++ test/Object/yaml2obj-invalid.yaml
> @@ -0,0 +1,2 @@
> +# RUN: not yaml2obj %s 2>&1 | FileCheck %s
> +# CHECK: Unknown document type!
> Index: include/llvm/Support/YAMLTraits.h
> ===================================================================
> --- include/llvm/Support/YAMLTraits.h
> +++ include/llvm/Support/YAMLTraits.h
> @@ -1418,8 +1418,8 @@
>                                 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;
>  }
>  


More information about the llvm-commits mailing list