Added YAML_fuzzer to CMakeLists + fixed .as<string> errors after testing

This commit is contained in:
BoloniniD 2021-05-26 10:56:51 +03:00
parent 1fbcfd9c6a
commit 84914ca12f
3 changed files with 31 additions and 4 deletions

View File

@ -57,7 +57,15 @@ void processNode(const YAML::Node & node, Poco::XML::Element & parent_xml_elemen
{ {
case YAML::NodeType::Scalar: case YAML::NodeType::Scalar:
{ {
auto value = node.as<std::string>(); std::string value;
try
{
value = node.as<std::string>();
}
catch (const YAML::TypedBadConversion<std::string>&)
{
throw Exception(ErrorCodes::CANNOT_PARSE_YAML, "YAMLParser has encountered node with value which cannot be represented as string and cannot continue parsing of the file");
}
Poco::AutoPtr<Poco::XML::Text> xml_value = xml_document->createTextNode(value); Poco::AutoPtr<Poco::XML::Text> xml_value = xml_document->createTextNode(value);
parent_xml_element.appendChild(xml_value); parent_xml_element.appendChild(xml_value);
break; break;
@ -110,13 +118,29 @@ void processNode(const YAML::Node & node, Poco::XML::Element & parent_xml_elemen
{ {
const auto & key_node = key_value_pair.first; const auto & key_node = key_value_pair.first;
const auto & value_node = key_value_pair.second; const auto & value_node = key_value_pair.second;
auto key = key_node.as<std::string>(); std::string key;
try
{
key = key_node.as<std::string>();
}
catch (const YAML::TypedBadConversion<std::string>&)
{
throw Exception(ErrorCodes::CANNOT_PARSE_YAML, "YAMLParser has encountered node with key which cannot be represented as string and cannot continue parsing of the file");
}
bool is_attribute = (key.starts_with(YAML_ATTRIBUTE_PREFIX) && value_node.IsScalar()); bool is_attribute = (key.starts_with(YAML_ATTRIBUTE_PREFIX) && value_node.IsScalar());
if (is_attribute) if (is_attribute)
{ {
/// we use substr(1) here to remove YAML_ATTRIBUTE_PREFIX from key /// we use substr(1) here to remove YAML_ATTRIBUTE_PREFIX from key
auto attribute_name = key.substr(1); auto attribute_name = key.substr(1);
auto value = value_node.as<std::string>(); std::string value;
try
{
value = value_node.as<std::string>();
}
catch (const YAML::TypedBadConversion<std::string>&)
{
throw Exception(ErrorCodes::CANNOT_PARSE_YAML, "YAMLParser has encountered node with value which cannot be represented as string and cannot continue parsing of the file");
}
parent_xml_element.setAttribute(attribute_name, value); parent_xml_element.setAttribute(attribute_name, value);
} }
else else

View File

@ -18,4 +18,7 @@ if (ENABLE_FUZZING)
add_executable(create_parser_fuzzer create_parser_fuzzer.cpp ${SRCS}) add_executable(create_parser_fuzzer create_parser_fuzzer.cpp ${SRCS})
target_link_libraries(create_parser_fuzzer PRIVATE clickhouse_parsers ${LIB_FUZZING_ENGINE}) target_link_libraries(create_parser_fuzzer PRIVATE clickhouse_parsers ${LIB_FUZZING_ENGINE})
add_executable(YAML_fuzzer YAML_fuzzer.cpp ${SRCS})
target_link_libraries(YAML_fuzzer PRIVATE clickhouse_parsers ${LIB_FUZZING_ENGINE})
endif () endif ()