Skip to content

Commit 8d84eda

Browse files
authored
Merge pull request #368 from maxmind/horgh/null-entry-data-list
Set entry parameter to NULL or valid memory
2 parents 01c6c0f + bc0cbd5 commit 8d84eda

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Changes.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 1.12.2
2+
3+
* `MMDB_get_entry_data_list()` now always sets the passed `entry_data_list`
4+
parameter to either `NULL` or valid memory. This makes it safe for
5+
callers to use `MMDB_free_entry_data_list()` on it even in case of error.
6+
In 1.12.0 `MMDB_get_entry_data_list()` was changed to not set this
7+
parameter to valid memory in additional error cases. That change caused
8+
segfaults for certain libraries that assumed it was safe to free memory
9+
on error. Doing so was never safe, but worked in some cases. This change
10+
makes such calls safe. Reported by Petr Pisar. GitHub
11+
maxmind/MaxMind-DB-Reader-XS#39.
12+
113
## 1.12.1 - 2025-01-08
214

315
* Added missing `cmake_uninstall.cmake.in` to the source distribution. This

src/maxminddb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,8 @@ int MMDB_get_metadata_as_entry_data_list(
16361636

16371637
int MMDB_get_entry_data_list(MMDB_entry_s *start,
16381638
MMDB_entry_data_list_s **const entry_data_list) {
1639+
*entry_data_list = NULL;
1640+
16391641
MMDB_data_pool_s *const pool = data_pool_new(MMDB_POOL_INIT_SIZE);
16401642
if (!pool) {
16411643
return MMDB_OUT_OF_MEMORY_ERROR;

t/bad_pointers_t.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ void run_tests(int mode, const char *mode_desc) {
2828
MMDB_INVALID_DATA_ERROR,
2929
"MMDB_get_entry_data_list returns MMDB_INVALID_DATA_ERROR for "
3030
"bad pointer in data section");
31+
32+
// This is not necessary as on error we should not need to free
33+
// anything. However test that it is safe to do so. See change in
34+
// 1.12.2.
35+
MMDB_free_entry_data_list(entry_data_list);
3136
}
3237

3338
{

0 commit comments

Comments
 (0)