"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "t/get_value_pointer_bug_t.c" between
libmaxminddb-1.5.0.tar.gz and libmaxminddb-1.5.2.tar.gz

About: libmaxminddb is a library that provides functions for working with MaxMind DB files (free GeoLite 2 or commercial GeoIP2).

get_value_pointer_bug_t.c  (libmaxminddb-1.5.0):get_value_pointer_bug_t.c  (libmaxminddb-1.5.2)
skipping to change at line 17 skipping to change at line 17
* *
* There is also the potential for a similar bug when looking up a value by * There is also the potential for a similar bug when looking up a value by
* path in an array. This is not tested (yet) as we don't have the right test * path in an array. This is not tested (yet) as we don't have the right test
* data for it. * data for it.
* *
* These tests are somewhat fragile since they depend on a specific data * These tests are somewhat fragile since they depend on a specific data
* layout in the database. Ideally the test would check that this layout * layout in the database. Ideally the test would check that this layout
* exists before checking to see if the lookups are correct. * exists before checking to see if the lookups are correct.
*/ */
void test_one_ip(MMDB_s *mmdb, const char *filename, const char *mode_desc, void test_one_ip(MMDB_s *mmdb,
char *ip, char *country_code) const char *filename,
{ const char *mode_desc,
char *ip,
char *country_code) {
MMDB_lookup_result_s result = MMDB_lookup_result_s result =
lookup_string_ok(mmdb, ip, filename, mode_desc); lookup_string_ok(mmdb, ip, filename, mode_desc);
MMDB_entry_data_s entry_data = MMDB_entry_data_s entry_data = data_ok(&result,
data_ok(&result, MMDB_DATA_TYPE_UTF8_STRING, "country{iso_code}", MMDB_DATA_TYPE_UTF8_STRING,
"country", "iso_code", NULL); "country{iso_code}",
"country",
"iso_code",
NULL);
if (ok(entry_data.has_data, "found data for country{iso_code}")) { if (ok(entry_data.has_data, "found data for country{iso_code}")) {
char *string = char *string =
mmdb_strndup(entry_data.utf8_string, entry_data.data_size); mmdb_strndup(entry_data.utf8_string, entry_data.data_size);
if (!string) { if (!string) {
ok(0, "mmdb_strndup() call failed"); ok(0, "mmdb_strndup() call failed");
exit(1); exit(1);
} }
if (!ok(strcmp(string, if (!ok(strcmp(string, country_code) == 0,
country_code) == 0, "iso_code is %s", country_code)) { "iso_code is %s",
country_code)) {
diag(" value is %s", string); diag(" value is %s", string);
} }
free(string); free(string);
} }
} }
void run_tests(int mode, const char *mode_desc) void run_tests(int mode, const char *mode_desc) {
{
const char *filename = "GeoIP2-City-Test.mmdb"; const char *filename = "GeoIP2-City-Test.mmdb";
const char *path = test_database_path(filename); const char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc); MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path); free((void *)path);
/* This exercises a bug where the entire top-level value is a pointer to /* This exercises a bug where the entire top-level value is a pointer to
* another part of the data section. */ * another part of the data section. */
test_one_ip(mmdb, filename, mode_desc, "2001:218::", "JP"); test_one_ip(mmdb, filename, mode_desc, "2001:218::", "JP");
/* This exercises a bug where one subnet's data shares part of the data /* This exercises a bug where one subnet's data shares part of the data
* with another subnet - in this case it is the "country" key (and others) * with another subnet - in this case it is the "country" key (and others)
* in the top level map. We are testing that the "country" key's value is * in the top level map. We are testing that the "country" key's value is
* handled correctly. The value _should_ be a pointer to another map. */ * handled correctly. The value _should_ be a pointer to another map. */
test_one_ip(mmdb, filename, mode_desc, "81.2.69.160", "GB"); test_one_ip(mmdb, filename, mode_desc, "81.2.69.160", "GB");
MMDB_close(mmdb); MMDB_close(mmdb);
free(mmdb); free(mmdb);
} }
int main(void) int main(void) {
{
plan(NO_PLAN); plan(NO_PLAN);
for_all_modes(&run_tests); for_all_modes(&run_tests);
done_testing(); done_testing();
} }
 End of changes. 6 change blocks. 
15 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)