[php-src] PR #26045: ext/dba: Reset LMDB cursor txn on missing fetch/exists during iteration

From: Date: Thu, 03 Dec 2026 07:48:06 +0000
Subject: [php-src] PR #26045: ext/dba: Reset LMDB cursor txn on missing fetch/exists during iteration
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-41387@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/26045 Author: hohphu8 In ext/dba/dba_lmdb.c, dba_fetch_lmdb() and dba_exists_lmdb() renew LMDB_IT(txn) when a key iteration cursor is active (LMDB_IT(cur) != NULL), and properly call mdb_txn_reset() on the success path, but unconditionally call mdb_txn_abort(LMDB_IT(txn)) when mdb_get() fails (such as MDB_NOTFOUND). That frees the cursor's transaction while LMDB_IT(cur) remains non-NULL, causing a use-after-free or double-free on the next dba_fetch(), dba_exists(), or dba_nextkey() call. In addition, dba_firstkey_lmdb() and dba_nextkey_lmdb() call mdb_txn_abort() before mdb_cursor_close() on error/end-of-iteration, and neither dba_close_lmdb() nor a repeated dba_firstkey_lmdb() closes an active cursor/transaction. Reset LMDB_IT(txn) instead of aborting it on mdb_get() failure in dba_fetch_lmdb() and dba_exists_lmdb() when LMDB_IT(cur) is active, matching the success path. Also close LMDB_IT(cur) before aborting LMDB_IT(txn) in dba_firstkey_lmdb() and dba_nextkey_lmdb(), and clean up any active cursor/transaction in dba_close_lmdb() and at the start of dba_firstkey_lmdb(). Note that this is separate from #21979 (which handles writes/deletes during iteration and dba_nextkey() without dba_firstkey()) and intentionally avoids touching those paths. Added a regression test (ext/dba/tests/dba_lmdb_fetch_exists_during_iteration.phpt) covering missing dba_fetch()/dba_exists() calls during active iteration, repeated dba_firstkey(), and closing mid-iteration. Verified dba_firstkey() followed by two missing dba_fetch() calls triggers an AddressSanitizer double-free before the fix, and all ext/dba/tests/*lmdb*.phpt tests (5/5) pass with zero leaks (ASAN_OPTIONS=detect_leaks=1) on PHP-8.4 (Debug + ZTS + ASan).

« previous php.git-pulls (#41387) next »