File: parser_test.cpp

package info (click to toggle)
yaml-cpp 0.7.0%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,400 kB
  • sloc: cpp: 23,299; ansic: 931; python: 196; makefile: 50
file content (64 lines) | stat: -rw-r--r-- 1,869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <yaml-cpp/depthguard.h>
#include "yaml-cpp/parser.h"
#include "yaml-cpp/exceptions.h"
#include "mock_event_handler.h"
#include "gtest/gtest.h"

using YAML::Parser;
using YAML::MockEventHandler;
using ::testing::NiceMock;
using ::testing::StrictMock;

TEST(ParserTest, Empty) {
    Parser parser;

    EXPECT_FALSE(parser);

    StrictMock<MockEventHandler> handler;
    EXPECT_FALSE(parser.HandleNextDocument(handler));
}

TEST(ParserTest, CVE_2017_5950) {
    std::string excessive_recursion;
    for (auto i = 0; i != 16384; ++i)
        excessive_recursion.push_back('[');
    std::istringstream input{excessive_recursion};
    Parser parser{input};

    NiceMock<MockEventHandler> handler;
    EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
}

TEST(ParserTest, CVE_2018_20573) {
    std::string excessive_recursion;
    for (auto i = 0; i != 20535; ++i)
        excessive_recursion.push_back('{');
    std::istringstream input{excessive_recursion};
    Parser parser{input};

    NiceMock<MockEventHandler> handler;
    EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
}

TEST(ParserTest, CVE_2018_20574) {
    std::string excessive_recursion;
    for (auto i = 0; i != 21989; ++i)
        excessive_recursion.push_back('{');
    std::istringstream input{excessive_recursion};
    Parser parser{input};

    NiceMock<MockEventHandler> handler;
    EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
}

TEST(ParserTest, CVE_2019_6285) {
    std::string excessive_recursion;
    for (auto i = 0; i != 23100; ++i)
        excessive_recursion.push_back('[');
    excessive_recursion.push_back('f');
    std::istringstream input{excessive_recursion};
    Parser parser{input};

    NiceMock<MockEventHandler> handler;
    EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
}