1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix bug and add test for dba_open same file twice (#17979)

Co-authored-by: Christian Schneider <schneider@search.ch>
This commit is contained in:
Christian Schneider
2025-03-11 12:08:53 +01:00
committed by GitHub
parent 09189026e6
commit 4ca6bde32f
2 changed files with 36 additions and 1 deletions

View File

@@ -57,6 +57,7 @@ ZEND_BEGIN_MODULE_GLOBALS(dba)
const char *default_handler;
const dba_handler *default_hptr;
HashTable connections;
unsigned int connection_counter;
ZEND_END_MODULE_GLOBALS(dba)
ZEND_DECLARE_MODULE_GLOBALS(dba)
@@ -571,7 +572,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
char *resource_key;
size_t resource_key_len = spprintf(&resource_key, 0,
"dba_%d_%s_%s_%s", persistent, ZSTR_VAL(path), ZSTR_VAL(mode), handler_str ? ZSTR_VAL(handler_str) : ""
"dba_%d_%u_%s_%s_%s", persistent, persistent ? 0 : DBA_G(connection_counter)++, ZSTR_VAL(path), ZSTR_VAL(mode), handler_str ? ZSTR_VAL(handler_str) : ""
);
if (persistent) {

View File

@@ -0,0 +1,34 @@
--TEST--
DBA open same read only file multiple times
--EXTENSIONS--
dba
--SKIPIF--
<?php
require_once __DIR__ . '/setup/setup_dba_tests.inc';
check_skip('cdb_make');
?>
--CONFLICTS--
test.cdb
--FILE--
<?php
echo "database handler: cdb\n";
$handler = 'cdb';
$db_filename = __DIR__.'/test.cdb';
if (($db_file=dba_open($db_filename, "r", $handler))!==FALSE) {
echo dba_fetch(1, $db_file);
if (($db_file2=dba_open($db_filename, "r", $handler))!==FALSE) {
echo dba_fetch(1, $db_file2);
echo dba_fetch(2, $db_file2);
dba_close($db_file2);
} else {
echo "Error opening database 2nd time\n";
}
echo dba_fetch(2, $db_file);
dba_close($db_file);
} else {
echo "Error opening database\n";
}
?>
--EXPECT--
database handler: cdb
1122