From 3f67497cbee187456ef01a1e5d824f5994e00b65 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Sun, 27 May 2018 10:34:22 +0300 Subject: [PATCH] geoipbackend: Check GeoIP_id_by_addr_gl and GeoIP_id_by_addr_v6_gl return value The return value must be greater than 0, all other indicate lookup failure. Fixes signal 11 crash. --- modules/geoipbackend/geoipbackend.cc | 41 ++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 9bd022365..80d2226ad 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -452,8 +452,11 @@ bool GeoIPBackend::get(DNSResourceRecord &r) { bool GeoIPBackend::queryCountry(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi) { if (gi.first == GEOIP_COUNTRY_EDITION || gi.first == GEOIP_LARGE_COUNTRY_EDITION) { - ret = GeoIP_code3_by_id(GeoIP_id_by_addr_gl(gi.second.get(), ip.c_str(), gl)); - return true; + int id; + if ((id = GeoIP_id_by_addr_gl(gi.second.get(), ip.c_str(), gl)) > 0) { + ret = GeoIP_code3_by_id(id); + return true; + } } else if (gi.first == GEOIP_REGION_EDITION_REV0 || gi.first == GEOIP_REGION_EDITION_REV1) { GeoIPRegion* gir = GeoIP_region_by_addr_gl(gi.second.get(), ip.c_str(), gl); @@ -476,8 +479,11 @@ bool GeoIPBackend::queryCountry(string &ret, GeoIPLookup* gl, const string &ip, bool GeoIPBackend::queryCountryV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi) { if (gi.first == GEOIP_COUNTRY_EDITION_V6 || gi.first == GEOIP_LARGE_COUNTRY_EDITION_V6) { - ret = GeoIP_code3_by_id(GeoIP_id_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl)); - return true; + int id; + if ((id = GeoIP_id_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl)) > 0) { + ret = GeoIP_code3_by_id(id); + return true; + } } else if (gi.first == GEOIP_REGION_EDITION_REV0 || gi.first == GEOIP_REGION_EDITION_REV1) { GeoIPRegion* gir = GeoIP_region_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl); @@ -500,8 +506,11 @@ bool GeoIPBackend::queryCountryV6(string &ret, GeoIPLookup* gl, const string &ip bool GeoIPBackend::queryCountry2(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi) { if (gi.first == GEOIP_COUNTRY_EDITION || gi.first == GEOIP_LARGE_COUNTRY_EDITION) { - ret = GeoIP_code_by_id(GeoIP_id_by_addr_gl(gi.second.get(), ip.c_str(), gl)); - return true; + int id; + if ((id = GeoIP_id_by_addr_gl(gi.second.get(), ip.c_str(), gl)) > 0) { + ret = GeoIP_code_by_id(id); + return true; + } } else if (gi.first == GEOIP_REGION_EDITION_REV0 || gi.first == GEOIP_REGION_EDITION_REV1) { GeoIPRegion* gir = GeoIP_region_by_addr_gl(gi.second.get(), ip.c_str(), gl); @@ -524,7 +533,11 @@ bool GeoIPBackend::queryCountry2(string &ret, GeoIPLookup* gl, const string &ip, bool GeoIPBackend::queryCountry2V6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi) { if (gi.first == GEOIP_COUNTRY_EDITION_V6 || gi.first == GEOIP_LARGE_COUNTRY_EDITION_V6) { - ret = GeoIP_code_by_id(GeoIP_id_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl)); + int id; + if ((id = GeoIP_id_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl)) > 0) { + ret = GeoIP_code_by_id(id); + return true; + } return true; } else if (gi.first == GEOIP_REGION_EDITION_REV0 || gi.first == GEOIP_REGION_EDITION_REV1) { @@ -548,8 +561,11 @@ bool GeoIPBackend::queryCountry2V6(string &ret, GeoIPLookup* gl, const string &i bool GeoIPBackend::queryContinent(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi) { if (gi.first == GEOIP_COUNTRY_EDITION || gi.first == GEOIP_LARGE_COUNTRY_EDITION) { - ret = GeoIP_continent_by_id(GeoIP_id_by_addr_gl(gi.second.get(), ip.c_str(), gl)); - return true; + int id; + if ((id = GeoIP_id_by_addr_gl(gi.second.get(), ip.c_str(), gl)) > 0) { + ret = GeoIP_continent_by_id(id); + return true; + } } else if (gi.first == GEOIP_REGION_EDITION_REV0 || gi.first == GEOIP_REGION_EDITION_REV1) { GeoIPRegion* gir = GeoIP_region_by_addr_gl(gi.second.get(), ip.c_str(), gl); @@ -572,8 +588,11 @@ bool GeoIPBackend::queryContinent(string &ret, GeoIPLookup* gl, const string &ip bool GeoIPBackend::queryContinentV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi) { if (gi.first == GEOIP_COUNTRY_EDITION_V6 || gi.first == GEOIP_LARGE_COUNTRY_EDITION_V6) { - ret = GeoIP_continent_by_id(GeoIP_id_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl)); - return true; + int id; + if ((id = GeoIP_id_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl)) > 0) { + ret = GeoIP_continent_by_id(id); + return true; + } } else if (gi.first == GEOIP_REGION_EDITION_REV0 || gi.first == GEOIP_REGION_EDITION_REV1) { GeoIPRegion* gir = GeoIP_region_by_addr_v6_gl(gi.second.get(), ip.c_str(), gl); -- 2.40.0