Skip to content

Commit a5f6f69

Browse files
committed
Check MMDB_get_metadata_as_entry_data_list return value
1 parent a93a344 commit a5f6f69

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CHANGELOG
77
* Improve the error handling when the user tries to open a directory
88
with the pure PHP reader.
99
* Improve the typehints on arrays in the PHPDocs.
10+
* The C extension now checks that the database metadata lookup was
11+
successful.
1012

1113
1.11.1 (2023-12-01)
1214
-------------------

ext/maxminddb.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,15 @@ PHP_METHOD(MaxMind_Db_Reader, metadata) {
336336
object_init_ex(return_value, metadata_ce);
337337

338338
MMDB_entry_data_list_s *entry_data_list;
339-
MMDB_get_metadata_as_entry_data_list(mmdb_obj->mmdb, &entry_data_list);
339+
int status =
340+
MMDB_get_metadata_as_entry_data_list(mmdb_obj->mmdb, &entry_data_list);
341+
if (status != MMDB_SUCCESS) {
342+
zend_throw_exception_ex(maxminddb_exception_ce,
343+
0 TSRMLS_CC,
344+
"Error while decoding metadata. %s",
345+
MMDB_strerror(status));
346+
return;
347+
}
340348

341349
zval metadata_array;
342350
const MMDB_entry_data_list_s *rv =

0 commit comments

Comments
 (0)