diff --git a/src/renderd_config.c b/src/renderd_config.c index a32266d5..85d7c21c 100644 --- a/src/renderd_config.c +++ b/src/renderd_config.c @@ -400,6 +400,11 @@ void process_renderd_sections(const char *config_file_name, renderd_config *conf exit(7); } + if (configs_dest[renderd_section_num].name != NULL) { + g_logger(G_LOG_LEVEL_CRITICAL, "Duplicate renderd config section names for section %i: %s & %s", renderd_section_num, configs_dest[renderd_section_num].name, section); + exit(7); + } + copy_string(section, &configs_dest[renderd_section_num].name, renderd_strlen + 2); process_config_int(ini, section, "ipport", &configs_dest[renderd_section_num].ipport, 0); diff --git a/tests/renderd_config_test.cpp b/tests/renderd_config_test.cpp index 1c173a96..dd848fc8 100644 --- a/tests/renderd_config_test.cpp +++ b/tests/renderd_config_test.cpp @@ -573,4 +573,26 @@ TEST_CASE("renderd_config config parser", "specific testing") found = err_log_lines.find("Specified socketname (" + renderd_socketname + ") exceeds maximum allowed length of " + std::to_string(renderd_socketname_maxlen) + "."); REQUIRE(found > -1); } + + SECTION("renderd.conf duplicate renderd section names", "should return 7") { + std::string renderd_conf = std::tmpnam(nullptr); + std::ofstream renderd_conf_file; + renderd_conf_file.open(renderd_conf); + renderd_conf_file << "[mapnik]\n[map]\n"; + renderd_conf_file << "[renderd0]\n[renderd]\n"; + renderd_conf_file.close(); + + std::string option = "--config " + renderd_conf; + std::string command = test_binary + " " + option; + + // flawfinder: ignore + FILE *pipe = popen(command.c_str(), "r"); + int status = pclose(pipe); + std::remove(renderd_conf.c_str()); + REQUIRE(WEXITSTATUS(status) == 7); + + err_log_lines = read_stderr(); + found = err_log_lines.find("Duplicate renderd config section names for section 0: renderd0 & renderd"); + REQUIRE(found > -1); + } }