Skip to content

Commit bde6db3

Browse files
committed
Disallow map section URIs which are substrings of preceeding map section URIs
1 parent e8ac8f1 commit bde6db3

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

etc/apache2/renderd-example-map.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,5 @@ Listen 8081
161161
# Off = a 404 is returned for that url instead.
162162
# Default: On
163163
#ModTileEnableDirtyURL Off
164-
164+
LogLevel debug
165165
</VirtualHost>

src/renderd_config.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ void process_map_sections(const char *config_file_name, xmlconfigitem *maps_dest
329329
g_logger(G_LOG_LEVEL_CRITICAL, "No map config sections were found in file: %s", config_file_name);
330330
exit(1);
331331
}
332+
333+
if (map_section_num > 0) {
334+
for (int x = 0; x < map_section_num; x++) {
335+
for (int y = x + 1; y <= map_section_num; y++) {
336+
if (strncmp(maps_dest[x].xmluri, maps_dest[y].xmluri, strlen(maps_dest[x].xmluri)) == 0) {
337+
g_logger(G_LOG_LEVEL_CRITICAL, "Specified URI ('%s' in map section '%s') must not be a substring of any subsequent map config section's URI, e.g., '%s' in map section '%s'.", maps_dest[x].xmluri, maps_dest[x].xmlname, maps_dest[y].xmluri, maps_dest[y].xmlname);
338+
exit(7);
339+
}
340+
}
341+
}
342+
}
332343
}
333344

334345
void process_mapnik_section(const char *config_file_name, renderd_config *config_dest)

tests/renderd_config_test.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ TEST_CASE("renderd_config config parser", "specific testing")
187187

188188
for (int i = 0; i <= XMLCONFIGS_MAX; i++) {
189189
renderd_conf_file << "[map" + std::to_string(i) + "]\n";
190+
renderd_conf_file << "uri=/" + std::to_string(i) + "\n";
190191
}
191192

192193
renderd_conf_file.close();
@@ -447,4 +448,30 @@ TEST_CASE("renderd_config config parser", "specific testing")
447448
REQUIRE(WEXITSTATUS(status) == 7);
448449
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("Duplicate renderd config section names for section 0: renderd0 & renderd"));
449450
}
451+
452+
SECTION("renderd.conf with overlapping URIs", "should return 7") {
453+
std::string map0_uri = GENERATE("", "/", "/map1", "/map2");
454+
455+
std::string renderd_conf = std::tmpnam(nullptr);
456+
std::ofstream renderd_conf_file;
457+
renderd_conf_file.open(renderd_conf);
458+
renderd_conf_file << "[mapnik]\n[renderd]\n";
459+
460+
renderd_conf_file << "[map0]\n";
461+
renderd_conf_file << "uri=" + map0_uri + "\n";
462+
renderd_conf_file << "[map1]\n";
463+
renderd_conf_file << "uri=/map1/1\n";
464+
renderd_conf_file << "[map2]\n";
465+
renderd_conf_file << "uri=/map2/2\n";
466+
467+
renderd_conf_file.close();
468+
469+
std::vector<std::string> argv = {"--config", renderd_conf};
470+
471+
int status = run_command(test_binary, argv);
472+
std::remove(renderd_conf.c_str());
473+
REQUIRE(WEXITSTATUS(status) == 7);
474+
REQUIRE_THAT(err_log_lines, Catch::Matchers::Contains("Specified URI ('" + map0_uri + "' in map section 'map0') must not be a substring of any subsequent map config section's URI, e.g., '/map"));
475+
}
450476
}
477+

0 commit comments

Comments
 (0)