]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
geoipbackend: Check GeoIP_id_by_addr_gl and GeoIP_id_by_addr_v6_gl return value 6677/head
authorAki Tuomi <cmouse@cmouse.fi>
Sun, 27 May 2018 07:39:45 +0000 (10:39 +0300)
committerAki Tuomi <cmouse@cmouse.fi>
Sun, 27 May 2018 07:50:56 +0000 (10:50 +0300)
The return value must be greater than 0, all other indicate lookup failure.
Fixes signal 11 crash.

modules/geoipbackend/geoipinterface-dat.cc

index a1754781af96b030e7935fdbb0e4e1eab246345c..650875f79298f2f7c31a387e33401c907546f6ac 100644 (file)
@@ -62,9 +62,12 @@ public:
     };
     if (d_db_type == GEOIP_COUNTRY_EDITION ||
         d_db_type == GEOIP_LARGE_COUNTRY_EDITION) {
-      ret = GeoIP_code3_by_id(GeoIP_id_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl));
-      gl.netmask = tmp_gl.netmask;
-      return true;
+      int id;
+      if ((id = GeoIP_id_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl)) > 0) {
+        ret = GeoIP_code3_by_id(id);
+        gl.netmask = tmp_gl.netmask;
+        return true;
+      }
     } else if (d_db_type == GEOIP_REGION_EDITION_REV0 ||
                d_db_type == GEOIP_REGION_EDITION_REV1) {
       GeoIPRegion* gir = GeoIP_region_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl);
@@ -91,9 +94,12 @@ public:
     };
     if (d_db_type == GEOIP_COUNTRY_EDITION_V6 ||
         d_db_type == GEOIP_LARGE_COUNTRY_EDITION_V6) {
-      ret = GeoIP_code3_by_id(GeoIP_id_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl));
-      gl.netmask = tmp_gl.netmask;
-      return true;
+      int id;
+      if ((id = GeoIP_id_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl)) > 0) {
+        ret = GeoIP_code3_by_id(id);
+        gl.netmask = tmp_gl.netmask;
+        return true;
+      }
     } else if (d_db_type == GEOIP_REGION_EDITION_REV0 ||
                d_db_type == GEOIP_REGION_EDITION_REV1) {
       GeoIPRegion* gir = GeoIP_region_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl);
@@ -120,9 +126,12 @@ public:
     };
     if (d_db_type == GEOIP_COUNTRY_EDITION ||
         d_db_type == GEOIP_LARGE_COUNTRY_EDITION) {
-      ret = GeoIP_code_by_id(GeoIP_id_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl));
-      gl.netmask = tmp_gl.netmask;
-      return true;
+      int id;
+      if ((id = GeoIP_id_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl)) > 0) {
+        ret = GeoIP_code_by_id(id);
+        gl.netmask = tmp_gl.netmask;
+        return true;
+      }
     } else if (d_db_type == GEOIP_REGION_EDITION_REV0 ||
                d_db_type == GEOIP_REGION_EDITION_REV1) {
       GeoIPRegion* gir = GeoIP_region_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl);
@@ -149,9 +158,12 @@ public:
     };
     if (d_db_type == GEOIP_COUNTRY_EDITION_V6 ||
         d_db_type == GEOIP_LARGE_COUNTRY_EDITION_V6) {
-      ret = GeoIP_code_by_id(GeoIP_id_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl));
-      gl.netmask = tmp_gl.netmask;
-      return true;
+      int id;
+      if ((id = GeoIP_id_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl)) > 0) {
+        ret = GeoIP_code_by_id(id);
+        gl.netmask = tmp_gl.netmask;
+        return true;
+      }
     } else if (d_db_type == GEOIP_REGION_EDITION_REV0 ||
                d_db_type == GEOIP_REGION_EDITION_REV1) {
       GeoIPRegion* gir = GeoIP_region_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl);
@@ -178,9 +190,12 @@ public:
     };
     if (d_db_type == GEOIP_COUNTRY_EDITION ||
         d_db_type == GEOIP_LARGE_COUNTRY_EDITION) {
-      ret = GeoIP_continent_by_id(GeoIP_id_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl));
-      gl.netmask = tmp_gl.netmask;
-      return true;
+      int id;
+      if ((id = GeoIP_id_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl)) > 0) {
+        ret = GeoIP_continent_by_id(id);
+        gl.netmask = tmp_gl.netmask;
+        return true;
+      }
     } else if (d_db_type == GEOIP_REGION_EDITION_REV0 ||
                d_db_type == GEOIP_REGION_EDITION_REV1) {
       GeoIPRegion* gir = GeoIP_region_by_addr_gl(d_gi.get(), ip.c_str(), &tmp_gl);
@@ -207,9 +222,12 @@ public:
     };
     if (d_db_type == GEOIP_COUNTRY_EDITION_V6 ||
         d_db_type == GEOIP_LARGE_COUNTRY_EDITION_V6) {
-      ret = GeoIP_continent_by_id(GeoIP_id_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl));
-      gl.netmask = tmp_gl.netmask;
-      return true;
+      int id;
+      if ((id = GeoIP_id_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl)) > 0) {
+        ret = GeoIP_continent_by_id(id);
+        gl.netmask = tmp_gl.netmask;
+        return true;
+      }
     } else if (d_db_type == GEOIP_REGION_EDITION_REV0 ||
                d_db_type == GEOIP_REGION_EDITION_REV1) {
       GeoIPRegion* gir = GeoIP_region_by_addr_v6_gl(d_gi.get(), ip.c_str(), &tmp_gl);