yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

fix(src): avoid possible infinite loop in LoadAll().

Open FedeDP opened this issue 1 year ago • 4 comments

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;
}

FedeDP avatar Sep 12 '24 12:09 FedeDP