diff --git a/src/utils/geo_lookup.cc b/src/utils/geo_lookup.cc index 4e06a1ec5..c7b27e3a5 100644 --- a/src/utils/geo_lookup.cc +++ b/src/utils/geo_lookup.cc @@ -66,6 +66,13 @@ bool GeoLookup::setDataBase(const std::string& filePath, std::string intGeo; #endif + /* A database may have been loaded already -- GeoLookup is a process wide + * singleton and SecGeoLookupDb can be used more than once, including on + * every re-parse of the configuration. Release it before loading the new + * one, otherwise the previous handle (and the mmap'ed database file) is + * leaked. */ + cleanUp(); + #ifdef WITH_MAXMIND int status = MMDB_open(filePath.c_str(), MMDB_MODE_MMAP, &mmdb); if (status != MMDB_SUCCESS) { diff --git a/test/test-cases/regression/config-secgeolookupdb.json b/test/test-cases/regression/config-secgeolookupdb.json new file mode 100644 index 000000000..c8a15db14 --- /dev/null +++ b/test/test-cases/regression/config-secgeolookupdb.json @@ -0,0 +1,51 @@ +[ + { + "enabled": 1, + "version_min": 300000, + "title": "Testing SecGeoLookupDb :: database informed twice [maxmind]", + "resource": "maxmind", + "client": { + "ip": "200.249.12.31", + "port": 123 + }, + "server": { + "ip": "200.249.12.31", + "port": 80 + }, + "request": { + "headers": { + "Host": "localhost", + "User-Agent": "curl/7.38.0", + "Accept": "*/*", + "Content-Length": "0" + }, + "uri": "/?key=value&key=other_value", + "method": "GET", + "body": [ + "" + ] + }, + "response": { + "headers": { + "Date": "Mon, 13 Jul 2015 20:02:41 GMT", + "Last-Modified": "Sun, 26 Oct 2014 22:33:37 GMT", + "Content-Type": "text/html", + "Content-Length": "8" + }, + "body": [ + "no need." + ] + }, + "expected": { + "debug_log": "Target value: \"Brazil\" \\(Variable: GEO:COUNTRY_NAME\\)", + "http_code": 200 + }, + "rules": [ + "SecRuleEngine On", + "SecGeoLookupDb test-cases/data/GeoIP2-City-Test.mmdb", + "SecGeoLookupDb test-cases/data/GeoIP2-City-Test.mmdb", + "SecRule REMOTE_ADDR \"@geoLookup\" \"id:1,pass,t:trim\"", + "SecRule GEO \"@contains test \" \"id:2,pass,t:trim\"" + ] + } +] diff --git a/test/test-suite.in b/test/test-suite.in index ebda49fb8..05fdba711 100644 --- a/test/test-suite.in +++ b/test/test-suite.in @@ -41,6 +41,7 @@ TESTS+=test/test-cases/regression/config-remove_by_msg.json TESTS+=test/test-cases/regression/config-remove_by_tag.json TESTS+=test/test-cases/regression/config-response_type.json TESTS+=test/test-cases/regression/config-secdefaultaction.json +TESTS+=test/test-cases/regression/config-secgeolookupdb.json TESTS+=test/test-cases/regression/config-secremoterules.json TESTS+=test/test-cases/regression/config-update-action-by-id.json TESTS+=test/test-cases/regression/config-update-target-by-id.json