2019-06-11 15:59:31 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
2019-06-11 15:59:31 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
2019-06-11 20:32:21 -07:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is only built and linked if GeoIP2 has been configured.
|
|
|
|
*/
|
|
|
|
#include <math.h>
|
|
|
|
#include <maxminddb.h>
|
2021-05-20 15:53:50 +02:00
|
|
|
#include <netinet/in.h>
|
2019-06-11 15:59:31 -07:00
|
|
|
|
2024-08-14 13:25:50 +02:00
|
|
|
#include <isc/log.h>
|
2019-06-11 20:32:21 -07:00
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/once.h>
|
|
|
|
#include <isc/sockaddr.h>
|
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/thread.h>
|
2019-06-11 15:59:31 -07:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
2019-06-11 20:32:21 -07:00
|
|
|
#include <dns/acl.h>
|
|
|
|
#include <dns/geoip.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure preserves state from the previous GeoIP lookup,
|
|
|
|
* so that successive lookups for the same data from the same IP
|
|
|
|
* address will not require repeated database lookups.
|
|
|
|
* This should improve performance somewhat.
|
|
|
|
*
|
|
|
|
* For all lookups we preserve pointers to the MMDB_lookup_result_s
|
|
|
|
* and MMDB_entry_s structures, a pointer to the database from which
|
|
|
|
* the lookup was answered, and a copy of the request address.
|
|
|
|
*
|
|
|
|
* If the next geoip ACL lookup is for the same database and from the
|
2024-08-14 13:25:50 +02:00
|
|
|
* same address, we can reuse the MMDB entry without repeating the
|
|
|
|
* lookup. This is for the case when a single query has to process
|
|
|
|
* multiple geoip ACLs: for example, when there are multiple views with
|
2019-06-11 20:32:21 -07:00
|
|
|
* match-clients statements that search for different countries.
|
|
|
|
*
|
|
|
|
* (XXX: Currently the persistent state is stored in thread specific
|
|
|
|
* memory, but it could more simply be stored in the client object.
|
|
|
|
* Also multiple entries could be stored in case the ACLs require
|
|
|
|
* searching in more than one GeoIP database.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct geoip_state {
|
|
|
|
uint16_t subtype;
|
|
|
|
const MMDB_s *db;
|
|
|
|
isc_netaddr_t addr;
|
|
|
|
MMDB_lookup_result_s mmresult;
|
|
|
|
MMDB_entry_s entry;
|
|
|
|
} geoip_state_t;
|
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
static thread_local geoip_state_t geoip_state = { 0 };
|
2019-06-11 20:32:21 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
set_state(const MMDB_s *db, const isc_netaddr_t *addr,
|
2019-12-02 11:42:50 +01:00
|
|
|
MMDB_lookup_result_s mmresult, MMDB_entry_s entry) {
|
|
|
|
geoip_state.db = db;
|
|
|
|
geoip_state.addr = *addr;
|
|
|
|
geoip_state.mmresult = mmresult;
|
|
|
|
geoip_state.entry = entry;
|
2019-06-11 20:32:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static geoip_state_t *
|
|
|
|
get_entry_for(MMDB_s *const db, const isc_netaddr_t *addr) {
|
|
|
|
isc_sockaddr_t sa;
|
|
|
|
MMDB_lookup_result_s match;
|
|
|
|
int err;
|
|
|
|
|
2019-12-02 11:42:50 +01:00
|
|
|
if (db == geoip_state.db && isc_netaddr_equal(addr, &geoip_state.addr))
|
|
|
|
{
|
|
|
|
return &geoip_state;
|
2019-06-11 20:32:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_sockaddr_fromnetaddr(&sa, addr, 0);
|
|
|
|
match = MMDB_lookup_sockaddr(db, &sa.type.sa, &err);
|
2020-01-13 14:32:19 +01:00
|
|
|
if (err != MMDB_SUCCESS || !match.found_entry) {
|
2019-06-11 20:32:21 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-02 11:42:50 +01:00
|
|
|
set_state(db, addr, match, match.entry);
|
2019-06-11 20:32:21 -07:00
|
|
|
|
2019-12-02 11:42:50 +01:00
|
|
|
return &geoip_state;
|
2019-06-11 20:32:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static dns_geoip_subtype_t
|
|
|
|
fix_subtype(const dns_geoip_databases_t *geoip, dns_geoip_subtype_t subtype) {
|
|
|
|
dns_geoip_subtype_t ret = subtype;
|
|
|
|
|
|
|
|
switch (subtype) {
|
|
|
|
case dns_geoip_countrycode:
|
|
|
|
if (geoip->city != NULL) {
|
|
|
|
ret = dns_geoip_city_countrycode;
|
|
|
|
} else if (geoip->country != NULL) {
|
|
|
|
ret = dns_geoip_country_code;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_countryname:
|
|
|
|
if (geoip->city != NULL) {
|
|
|
|
ret = dns_geoip_city_countryname;
|
|
|
|
} else if (geoip->country != NULL) {
|
|
|
|
ret = dns_geoip_country_name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_continentcode:
|
|
|
|
if (geoip->city != NULL) {
|
|
|
|
ret = dns_geoip_city_continentcode;
|
|
|
|
} else if (geoip->country != NULL) {
|
|
|
|
ret = dns_geoip_country_continentcode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_continent:
|
|
|
|
if (geoip->city != NULL) {
|
|
|
|
ret = dns_geoip_city_continent;
|
|
|
|
} else if (geoip->country != NULL) {
|
|
|
|
ret = dns_geoip_country_continent;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_region:
|
|
|
|
if (geoip->city != NULL) {
|
|
|
|
ret = dns_geoip_city_region;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dns_geoip_regionname:
|
|
|
|
if (geoip->city != NULL) {
|
|
|
|
ret = dns_geoip_city_regionname;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MMDB_s *
|
|
|
|
geoip2_database(const dns_geoip_databases_t *geoip,
|
|
|
|
dns_geoip_subtype_t subtype) {
|
|
|
|
switch (subtype) {
|
|
|
|
case dns_geoip_country_code:
|
|
|
|
case dns_geoip_country_name:
|
|
|
|
case dns_geoip_country_continentcode:
|
|
|
|
case dns_geoip_country_continent:
|
|
|
|
return geoip->country;
|
|
|
|
|
|
|
|
case dns_geoip_city_countrycode:
|
|
|
|
case dns_geoip_city_countryname:
|
|
|
|
case dns_geoip_city_continentcode:
|
|
|
|
case dns_geoip_city_continent:
|
|
|
|
case dns_geoip_city_region:
|
|
|
|
case dns_geoip_city_regionname:
|
|
|
|
case dns_geoip_city_name:
|
|
|
|
case dns_geoip_city_postalcode:
|
|
|
|
case dns_geoip_city_timezonecode:
|
|
|
|
case dns_geoip_city_metrocode:
|
|
|
|
case dns_geoip_city_areacode:
|
|
|
|
return geoip->city;
|
|
|
|
|
|
|
|
case dns_geoip_isp_name:
|
|
|
|
return geoip->isp;
|
|
|
|
|
|
|
|
case dns_geoip_as_asnum:
|
|
|
|
case dns_geoip_org_name:
|
|
|
|
return geoip->as;
|
|
|
|
|
|
|
|
case dns_geoip_domain_name:
|
|
|
|
return geoip->domain;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* All other subtypes are unavailable in GeoIP2.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
match_string(MMDB_entry_data_s *value, const char *str) {
|
|
|
|
REQUIRE(str != NULL);
|
|
|
|
|
|
|
|
if (value == NULL || !value->has_data ||
|
|
|
|
value->type != MMDB_DATA_TYPE_UTF8_STRING ||
|
|
|
|
value->utf8_string == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strncasecmp(value->utf8_string, str, value->data_size) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
match_int(MMDB_entry_data_s *value, const uint32_t ui32) {
|
|
|
|
if (value == NULL || !value->has_data ||
|
|
|
|
(value->type != MMDB_DATA_TYPE_UINT32 &&
|
|
|
|
value->type != MMDB_DATA_TYPE_UINT16))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value->uint32 == ui32;
|
|
|
|
}
|
|
|
|
|
2019-06-11 15:59:31 -07:00
|
|
|
bool
|
|
|
|
dns_geoip_match(const isc_netaddr_t *reqaddr,
|
|
|
|
const dns_geoip_databases_t *geoip,
|
|
|
|
const dns_geoip_elem_t *elt) {
|
2019-06-11 20:32:21 -07:00
|
|
|
MMDB_s *db = NULL;
|
|
|
|
MMDB_entry_data_s value;
|
|
|
|
geoip_state_t *state = NULL;
|
|
|
|
dns_geoip_subtype_t subtype;
|
|
|
|
const char *s = NULL;
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
int ret;
|
2019-06-11 20:32:21 -07:00
|
|
|
|
|
|
|
REQUIRE(reqaddr != NULL);
|
|
|
|
REQUIRE(elt != NULL);
|
|
|
|
REQUIRE(geoip != NULL);
|
|
|
|
|
|
|
|
subtype = fix_subtype(geoip, elt->subtype);
|
|
|
|
db = geoip2_database(geoip, subtype);
|
|
|
|
if (db == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = get_entry_for(db, reqaddr);
|
|
|
|
if (state == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (subtype) {
|
|
|
|
case dns_geoip_country_code:
|
|
|
|
case dns_geoip_city_countrycode:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "country",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"iso_code", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_country_name:
|
|
|
|
case dns_geoip_city_countryname:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "country", "names",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"en", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_country_continentcode:
|
|
|
|
case dns_geoip_city_continentcode:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "continent", "code",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
(char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_country_continent:
|
|
|
|
case dns_geoip_city_continent:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "continent",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"names", "en", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_region:
|
|
|
|
case dns_geoip_city_region:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "subdivisions", "0",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"iso_code", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_regionname:
|
|
|
|
case dns_geoip_city_regionname:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "subdivisions", "0",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"names", "en", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_city_name:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "city", "names",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"en", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_city_postalcode:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "postal", "code",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
(char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_city_timezonecode:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "location",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"time_zone", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_city_metrocode:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value, "location",
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"metro_code", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_isp_name:
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
ret = MMDB_get_value(&state->entry, &value, "isp", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_as_asnum:
|
|
|
|
INSIST(elt->as_string != NULL);
|
|
|
|
|
|
|
|
ret = MMDB_get_value(&state->entry, &value,
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"autonomous_system_number", (char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
int i;
|
2019-06-11 20:32:21 -07:00
|
|
|
s = elt->as_string;
|
|
|
|
if (strncasecmp(s, "AS", 2) == 0) {
|
|
|
|
s += 2;
|
|
|
|
}
|
|
|
|
i = strtol(s, NULL, 10);
|
|
|
|
return match_int(&value, i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_org_name:
|
|
|
|
ret = MMDB_get_value(&state->entry, &value,
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
"autonomous_system_organization",
|
|
|
|
(char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_geoip_domain_name:
|
Fix passing NULL after the last typed argument to a variadic function leads to undefined behaviour.
From Cppcheck:
Passing NULL after the last typed argument to a variadic function leads to
undefined behaviour. The C99 standard, in section 7.15.1.1, states that if the
type used by va_arg() is not compatible with the type of the actual next
argument (as promoted according to the default argument promotions), the
behavior is undefined. The value of the NULL macro is an implementation-defined
null pointer constant (7.17), which can be any integer constant expression with
the value 0, or such an expression casted to (void*) (6.3.2.3). This includes
values like 0, 0L, or even 0LL.In practice on common architectures, this will
cause real crashes if sizeof(int) != sizeof(void*), and NULL is defined to 0 or
any other null pointer constant that promotes to int. To reproduce you might be
able to use this little code example on 64bit platforms. If the output includes
"ERROR", the sentinel had only 4 out of 8 bytes initialized to zero and was not
detected as the final argument to stop argument processing via
va_arg(). Changing the 0 to (void*)0 or 0L will make the "ERROR" output go away.
void f(char *s, ...) {
va_list ap;
va_start(ap,s);
for (;;) {
char *p = va_arg(ap,char*);
printf("%018p, %s\n", p, (long)p & 255 ? p : "");
if(!p) break;
}
va_end(ap);
}
void g() {
char *s2 = "x";
char *s3 = "ERROR";
// changing 0 to 0L for the 7th argument (which is intended to act as
// sentinel) makes the error go away on x86_64
f("first", s2, s2, s2, s2, s2, 0, s3, (char*)0);
}
void h() {
int i;
volatile unsigned char a[1000];
for (i = 0; i<sizeof(a); i++)
a[i] = -1;
}
int main() {
h();
g();
return 0;
}
2019-09-27 10:00:46 +02:00
|
|
|
ret = MMDB_get_value(&state->entry, &value, "domain",
|
|
|
|
(char *)0);
|
2019-06-11 20:32:21 -07:00
|
|
|
if (ret == MMDB_SUCCESS) {
|
|
|
|
return match_string(&value, elt->as_string);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* For any other subtype, we assume the database was
|
|
|
|
* unavailable and return false.
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-11 15:59:31 -07:00
|
|
|
|
2019-06-11 20:32:21 -07:00
|
|
|
/*
|
|
|
|
* No database matched: return false.
|
|
|
|
*/
|
2019-06-11 15:59:31 -07:00
|
|
|
return false;
|
|
|
|
}
|