[php-src] PHP-8.6: dba: fix GH-24641 (NULL dereferencement with ndbm backend)

From: Date: Sat, 24 Oct 2026 16:44:15 +0000
Subject: [php-src] PHP-8.6: dba: fix GH-24641 (NULL dereferencement with ndbm backend)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142682@lists.php.net to get a copy of this message
Author: Gina Peter Banyard (Girgias) Date: 2026-10-24T17:40:44+01:00 Commit: https://github.com/php/php-src/commit/b309533729f82df48ca1e9a96ddefb6c911f31ac Raw diff: https://github.com/php/php-src/commit/b309533729f82df48ca1e9a96ddefb6c911f31ac.diff dba: fix GH-24641 (NULL dereferencement with ndbm backend) Return FAILURE in DBA_OPEN_FUNC(ndbm) if dbm_open() returns a NULL pointer. Closes GH-24641 Closes GH-24652 Changed paths: A ext/dba/tests/gh24641.phpt M NEWS M ext/dba/dba_ndbm.c Diff: diff --git a/NEWS b/NEWS index fb54e6dd3e6c..38476ae63111 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,10 @@ PHP NEWS . Fixed bug GH-24350 (MINIT reads a stale external tz database after an in-process module restart). (Lazizbek Ergashev) +- DBA: + . Fixed bug GH-24641 (ndbm backend never checks dbm_open() return value, + NULL deref on first use after a failed open). (Girgias) + - DOM: . Fixed bug GH-23352 (UAF reading an attribute value node retained across DOMDocument::adoptNode()). (David Carlier) diff --git a/ext/dba/dba_ndbm.c b/ext/dba/dba_ndbm.c index 40ae304cb7d2..58e4893ec2d2 100644 --- a/ext/dba/dba_ndbm.c +++ b/ext/dba/dba_ndbm.c @@ -53,6 +53,9 @@ DBA_OPEN_FUNC(ndbm) } dbf = dbm_open(ZSTR_VAL(info->path), gmode, filemode); + if (dbf == NULL) { + return FAILURE; + } pinfo->dbf = dbf; return SUCCESS; diff --git a/ext/dba/tests/gh24641.phpt b/ext/dba/tests/gh24641.phpt new file mode 100644 index 000000000000..e7479b64333c --- /dev/null +++ b/ext/dba/tests/gh24641.phpt @@ -0,0 +1,30 @@ +--TEST-- +GH-24641 (ndbm backend never checks dbm_open() return value, NULL deref on first use after a failed open) +--EXTENSIONS-- +dba +--FILE-- +<?php + +file_put_contents(__DIR__ . '/gh24641', 'not a valid ndbm/gdbm database, just plain text'); + +foreach (dba_handlers() as $handler) { + /* Suppress warnings */ + $db = @dba_open(__DIR__ . '/gh24641', 'r', $handler); + /* Expected as this file is not a proper db file */ + if ($db === false) { + continue; + } + /* Some drivers just don't care */ + dba_firstkey($db); // SEGV + dba_close($db); +} + +?> +DONE +--CLEAN-- +<?php +@unlink(__DIR__ . '/gh24641'); +@unlink(__DIR__ . '/gh24641-lock'); +?> +--EXPECT-- +DONE

« previous php.cvs (#142682) next »