From b8f93b4ce2a7178d81d481c1b9557f7ca7569078 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 23 Jan 2025 15:01:08 -0800 Subject: [PATCH] Check MMDB_get_metadata_as_entry_data_list return value --- HISTORY.rst | 2 ++ extension/maxminddb.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 0456b44..4f262dc 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,8 @@ History ++++++++++++++++++ * The vendored ``libmaxminddb`` has been updated to 1.12.2. +* The C extension now checks that the database metadata lookup was + successful. 2.6.3 (2025-01-09) ++++++++++++++++++ diff --git a/extension/maxminddb.c b/extension/maxminddb.c index d685792..5faf045 100644 --- a/extension/maxminddb.c +++ b/extension/maxminddb.c @@ -351,7 +351,14 @@ static PyObject *Reader_metadata(PyObject *self, PyObject *UNUSED(args)) { } MMDB_entry_data_list_s *entry_data_list; - MMDB_get_metadata_as_entry_data_list(mmdb_obj->mmdb, &entry_data_list); + int status = + MMDB_get_metadata_as_entry_data_list(mmdb_obj->mmdb, &entry_data_list); + if (status != MMDB_SUCCESS) { + PyErr_Format(MaxMindDB_error, + "Error decoding metadata. %s", + MMDB_strerror(status)); + return NULL; + } MMDB_entry_data_list_s *original_entry_data_list = entry_data_list; PyObject *metadata_dict = from_entry_data_list(&entry_data_list);