1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00
SqMod/vendor/MaxmindDB/t/bad_pointers_t.c

59 lines
1.7 KiB
C
Raw Normal View History

2021-01-31 17:48:31 +01:00
#include "maxminddb_test_helper.h"
2021-08-22 19:15:19 +02:00
void run_tests(int mode, const char *mode_desc) {
2021-01-31 17:48:31 +01:00
const char *filename = "MaxMind-DB-test-broken-pointers-24.mmdb";
const char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
{
const char *ip = "1.1.1.16";
MMDB_lookup_result_s result =
lookup_string_ok(mmdb, ip, filename, mode_desc);
MMDB_entry_data_s entry_data;
int status = MMDB_get_value(&result.entry, &entry_data, NULL);
2021-08-22 19:15:19 +02:00
cmp_ok(status,
"==",
MMDB_INVALID_DATA_ERROR,
"MMDB_get_value returns MMDB_INVALID_DATA_ERROR for bad pointer "
"in data section");
2021-01-31 17:48:31 +01:00
MMDB_entry_data_list_s *entry_data_list;
status = MMDB_get_entry_data_list(&result.entry, &entry_data_list);
2021-08-22 19:15:19 +02:00
cmp_ok(status,
"==",
MMDB_INVALID_DATA_ERROR,
"MMDB_get_entry_data_list returns MMDB_INVALID_DATA_ERROR for "
"bad pointer in data section");
2021-01-31 17:48:31 +01:00
MMDB_free_entry_data_list(entry_data_list);
}
{
const char *ip = "1.1.1.32";
int gai_error, mmdb_error;
MMDB_lookup_result_s UNUSED(result) =
MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
2021-08-22 19:15:19 +02:00
cmp_ok(mmdb_error,
"==",
MMDB_CORRUPT_SEARCH_TREE_ERROR,
"MMDB_lookup_string sets mmdb_error to "
"MMDB_CORRUPT_SEARCH_TREE_ERROR when a search tree record "
"points outside the data section");
2021-01-31 17:48:31 +01:00
}
MMDB_close(mmdb);
free(mmdb);
}
2021-08-22 19:15:19 +02:00
int main(void) {
2021-01-31 17:48:31 +01:00
plan(NO_PLAN);
for_all_modes(&run_tests);
done_testing();
}