Description
salt.utils.jinja.SerializerExtension.load_yaml crashes with AttributeError: 'NoneType' object has no attribute 'splitlines' instead of raising the intended TemplateRuntimeError when YAML parsing fails and PyYAML's libyaml (C) loader is in use.
The C loader populates the exception's problem_mark but leaves problem_mark.buffer as None. load_yaml only guards against problem_mark being absent (except AttributeError), so with the C loader it takes the else branch and passes buffer=None into salt.utils.stringutils.get_context(), which then calls None.splitlines().
This affects the load_yaml filter and the {% load_yaml %} / {% import_yaml %} tags whenever the YAML is invalid and libyaml is installed (the default in most packages).
Setup
Steps to Reproduce the behavior
Render a jinja template that loads malformed YAML:
{% load_yaml as data %}{foo, bar: baz}{% endload %}{{ data }}
Minimal reproduction:
from jinja2 import Environment
from salt.utils.jinja import SerializerExtension
env = Environment(extensions=[SerializerExtension])
env.from_string("{% load_yaml as d %}{a, b: c}{% endload %}{{ d }}").render()
With the libyaml loader active this raises AttributeError: 'NoneType' object has no attribute 'splitlines' from salt/utils/stringutils.py instead of a TemplateRuntimeError.
Expected behavior
load_yaml raises jinja2.exceptions.TemplateRuntimeError ("Encountered error loading yaml: ...") regardless of which YAML loader is active.
Versions Report
Reproduced on 3006.26; the same error-handling code is present on current master.
Description
salt.utils.jinja.SerializerExtension.load_yamlcrashes withAttributeError: 'NoneType' object has no attribute 'splitlines'instead of raising the intendedTemplateRuntimeErrorwhen YAML parsing fails and PyYAML's libyaml (C) loader is in use.The C loader populates the exception's
problem_markbut leavesproblem_mark.bufferasNone.load_yamlonly guards againstproblem_markbeing absent (except AttributeError), so with the C loader it takes theelsebranch and passesbuffer=Noneintosalt.utils.stringutils.get_context(), which then callsNone.splitlines().This affects the
load_yamlfilter and the{% load_yaml %}/{% import_yaml %}tags whenever the YAML is invalid and libyaml is installed (the default in most packages).Setup
Steps to Reproduce the behavior
Render a jinja template that loads malformed YAML:
Minimal reproduction:
With the libyaml loader active this raises
AttributeError: 'NoneType' object has no attribute 'splitlines'fromsalt/utils/stringutils.pyinstead of aTemplateRuntimeError.Expected behavior
load_yamlraisesjinja2.exceptions.TemplateRuntimeError("Encountered error loading yaml: ...") regardless of which YAML loader is active.Versions Report
Reproduced on 3006.26; the same error-handling code is present on current master.