|
| 1 | +#include "maxminddb_test_helper.h" |
| 2 | + |
| 3 | +void test_empty_map_last_in_metadata(void) { |
| 4 | + char *db_file = |
| 5 | + bad_database_path("libmaxminddb-empty-map-last-in-metadata.mmdb"); |
| 6 | + |
| 7 | + MMDB_s mmdb; |
| 8 | + int status = MMDB_open(db_file, MMDB_MODE_MMAP, &mmdb); |
| 9 | + cmp_ok(status, |
| 10 | + "==", |
| 11 | + MMDB_SUCCESS, |
| 12 | + "opened MMDB with empty map at end of metadata"); |
| 13 | + |
| 14 | + if (status != MMDB_SUCCESS) { |
| 15 | + diag("MMDB_open failed: %s", MMDB_strerror(status)); |
| 16 | + free(db_file); |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + int gai_error, mmdb_error; |
| 21 | + MMDB_lookup_string(&mmdb, "1.2.3.4", &gai_error, &mmdb_error); |
| 22 | + cmp_ok(mmdb_error, "==", MMDB_SUCCESS, "lookup succeeded"); |
| 23 | + |
| 24 | + MMDB_close(&mmdb); |
| 25 | + free(db_file); |
| 26 | +} |
| 27 | + |
| 28 | +void test_empty_array_last_in_metadata(void) { |
| 29 | + char *db_file = |
| 30 | + bad_database_path("libmaxminddb-empty-array-last-in-metadata.mmdb"); |
| 31 | + |
| 32 | + MMDB_s mmdb; |
| 33 | + int status = MMDB_open(db_file, MMDB_MODE_MMAP, &mmdb); |
| 34 | + cmp_ok(status, |
| 35 | + "==", |
| 36 | + MMDB_SUCCESS, |
| 37 | + "opened MMDB with empty array at end of metadata"); |
| 38 | + |
| 39 | + if (status != MMDB_SUCCESS) { |
| 40 | + diag("MMDB_open failed: %s", MMDB_strerror(status)); |
| 41 | + free(db_file); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + int gai_error, mmdb_error; |
| 46 | + MMDB_lookup_string(&mmdb, "1.2.3.4", &gai_error, &mmdb_error); |
| 47 | + cmp_ok(mmdb_error, "==", MMDB_SUCCESS, "lookup succeeded"); |
| 48 | + |
| 49 | + MMDB_close(&mmdb); |
| 50 | + free(db_file); |
| 51 | +} |
| 52 | + |
| 53 | +int main(void) { |
| 54 | + plan(NO_PLAN); |
| 55 | + test_empty_map_last_in_metadata(); |
| 56 | + test_empty_array_last_in_metadata(); |
| 57 | + done_testing(); |
| 58 | +} |
0 commit comments