Skip to content

Commit

Permalink
Merge pull request #368 from maxmind/horgh/null-entry-data-list
Browse files Browse the repository at this point in the history
Set entry parameter to NULL or valid memory
  • Loading branch information
oschwald authored Jan 10, 2025
2 parents 01c6c0f + bc0cbd5 commit 8d84eda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.12.2

* `MMDB_get_entry_data_list()` now always sets the passed `entry_data_list`
parameter to either `NULL` or valid memory. This makes it safe for
callers to use `MMDB_free_entry_data_list()` on it even in case of error.
In 1.12.0 `MMDB_get_entry_data_list()` was changed to not set this
parameter to valid memory in additional error cases. That change caused
segfaults for certain libraries that assumed it was safe to free memory
on error. Doing so was never safe, but worked in some cases. This change
makes such calls safe. Reported by Petr Pisar. GitHub
maxmind/MaxMind-DB-Reader-XS#39.

## 1.12.1 - 2025-01-08

* Added missing `cmake_uninstall.cmake.in` to the source distribution. This
Expand Down
2 changes: 2 additions & 0 deletions src/maxminddb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,8 @@ int MMDB_get_metadata_as_entry_data_list(

int MMDB_get_entry_data_list(MMDB_entry_s *start,
MMDB_entry_data_list_s **const entry_data_list) {
*entry_data_list = NULL;

MMDB_data_pool_s *const pool = data_pool_new(MMDB_POOL_INIT_SIZE);
if (!pool) {
return MMDB_OUT_OF_MEMORY_ERROR;
Expand Down
5 changes: 5 additions & 0 deletions t/bad_pointers_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ void run_tests(int mode, const char *mode_desc) {
MMDB_INVALID_DATA_ERROR,
"MMDB_get_entry_data_list returns MMDB_INVALID_DATA_ERROR for "
"bad pointer in data section");

// This is not necessary as on error we should not need to free
// anything. However test that it is safe to do so. See change in
// 1.12.2.
MMDB_free_entry_data_list(entry_data_list);
}

{
Expand Down

0 comments on commit 8d84eda

Please sign in to comment.