"Fossies" - the Fresh Open Source Software Archive

Member "libmaxminddb-1.5.2/t/bad_pointers_t.c" (18 Feb 2021, 1742 Bytes) of package /linux/misc/libmaxminddb-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "bad_pointers_t.c": 1.5.0_vs_1.5.2.

    1 #include "maxminddb_test_helper.h"
    2 
    3 void run_tests(int mode, const char *mode_desc) {
    4     const char *filename = "MaxMind-DB-test-broken-pointers-24.mmdb";
    5     const char *path = test_database_path(filename);
    6     MMDB_s *mmdb = open_ok(path, mode, mode_desc);
    7     free((void *)path);
    8 
    9     {
   10         const char *ip = "1.1.1.16";
   11         MMDB_lookup_result_s result =
   12             lookup_string_ok(mmdb, ip, filename, mode_desc);
   13 
   14         MMDB_entry_data_s entry_data;
   15         int status = MMDB_get_value(&result.entry, &entry_data, NULL);
   16 
   17         cmp_ok(status,
   18                "==",
   19                MMDB_INVALID_DATA_ERROR,
   20                "MMDB_get_value returns MMDB_INVALID_DATA_ERROR for bad pointer "
   21                "in data section");
   22 
   23         MMDB_entry_data_list_s *entry_data_list;
   24         status = MMDB_get_entry_data_list(&result.entry, &entry_data_list);
   25 
   26         cmp_ok(status,
   27                "==",
   28                MMDB_INVALID_DATA_ERROR,
   29                "MMDB_get_entry_data_list returns MMDB_INVALID_DATA_ERROR for "
   30                "bad pointer in data section");
   31 
   32         MMDB_free_entry_data_list(entry_data_list);
   33     }
   34 
   35     {
   36         const char *ip = "1.1.1.32";
   37 
   38         int gai_error, mmdb_error;
   39         MMDB_lookup_result_s UNUSED(result) =
   40             MMDB_lookup_string(mmdb, ip, &gai_error, &mmdb_error);
   41 
   42         cmp_ok(mmdb_error,
   43                "==",
   44                MMDB_CORRUPT_SEARCH_TREE_ERROR,
   45                "MMDB_lookup_string sets mmdb_error to "
   46                "MMDB_CORRUPT_SEARCH_TREE_ERROR when a search tree record "
   47                "points outside the data section");
   48     }
   49 
   50     MMDB_close(mmdb);
   51     free(mmdb);
   52 }
   53 
   54 int main(void) {
   55     plan(NO_PLAN);
   56     for_all_modes(&run_tests);
   57     done_testing();
   58 }