yaml-cpp
yaml-cpp copied to clipboard
fix(src): avoid possible infinite loop in LoadAll().
Leave at first empty root.
This avoids an infinite loop in case of HandleNextDocument returning true even if the document has errors, basically because no token.type gets matched in SingleDocParser::HandleNode, leading to eventHandler.OnNull(mark, anchor); being called indefinitely at each iteration, pushing a null node to documents vector.
Another solution would be to add a m_scanner.pop(); in the default switch case in SingleDocParser::HandleNode to make sure we always consume the current token.
The behavior causes this issue: https://github.com/falcosecurity/falco/issues/3281
Easily reproducible with a simple c++ example:
#include <yaml-cpp/yaml.h>
int main() {
static const std::string yml = R"(
,
)";
YAML::LoadAll(yml);
return 0;
}