You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

2 months ago
  1. #include <yaml-cpp/depthguard.h>
  2. #include "yaml-cpp/parser.h"
  3. #include "yaml-cpp/exceptions.h"
  4. #include "mock_event_handler.h"
  5. #include "gtest/gtest.h"
  6. using YAML::Parser;
  7. using YAML::MockEventHandler;
  8. using ::testing::NiceMock;
  9. using ::testing::StrictMock;
  10. TEST(ParserTest, Empty) {
  11. Parser parser;
  12. EXPECT_FALSE(parser);
  13. StrictMock<MockEventHandler> handler;
  14. EXPECT_FALSE(parser.HandleNextDocument(handler));
  15. }
  16. TEST(ParserTest, CVE_2017_5950) {
  17. std::string excessive_recursion;
  18. for (auto i = 0; i != 16384; ++i)
  19. excessive_recursion.push_back('[');
  20. std::istringstream input{excessive_recursion};
  21. Parser parser{input};
  22. NiceMock<MockEventHandler> handler;
  23. EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
  24. }
  25. TEST(ParserTest, CVE_2018_20573) {
  26. std::string excessive_recursion;
  27. for (auto i = 0; i != 20535; ++i)
  28. excessive_recursion.push_back('{');
  29. std::istringstream input{excessive_recursion};
  30. Parser parser{input};
  31. NiceMock<MockEventHandler> handler;
  32. EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
  33. }
  34. TEST(ParserTest, CVE_2018_20574) {
  35. std::string excessive_recursion;
  36. for (auto i = 0; i != 21989; ++i)
  37. excessive_recursion.push_back('{');
  38. std::istringstream input{excessive_recursion};
  39. Parser parser{input};
  40. NiceMock<MockEventHandler> handler;
  41. EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
  42. }
  43. TEST(ParserTest, CVE_2019_6285) {
  44. std::string excessive_recursion;
  45. for (auto i = 0; i != 23100; ++i)
  46. excessive_recursion.push_back('[');
  47. excessive_recursion.push_back('f');
  48. std::istringstream input{excessive_recursion};
  49. Parser parser{input};
  50. NiceMock<MockEventHandler> handler;
  51. EXPECT_THROW(parser.HandleNextDocument(handler), YAML::DeepRecursion);
  52. }