@@ -262,9 +262,10 @@ static void dba_close(dba_info *info)
262
262
if (info -> hnd ) {
263
263
info -> hnd -> close (info );
264
264
}
265
- if (info -> path ) {
266
- pefree (info -> path , info -> flags & DBA_PERSISTENT );
267
- }
265
+ ZEND_ASSERT (info -> path );
266
+ zend_string_release_ex (info -> path , info -> flags & DBA_PERSISTENT );
267
+ info -> path = NULL ;
268
+
268
269
if (info -> fp && info -> fp != info -> lock .fp ) {
269
270
if (info -> flags & DBA_PERSISTENT ) {
270
271
php_stream_pclose (info -> fp );
@@ -431,7 +432,7 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
431
432
/* }}} */
432
433
433
434
/* {{{ php_find_dbm */
434
- static dba_info * php_dba_find (const char * path )
435
+ static dba_info * php_dba_find (const zend_string * path )
435
436
{
436
437
zend_resource * le ;
437
438
dba_info * info ;
@@ -444,7 +445,7 @@ static dba_info *php_dba_find(const char* path)
444
445
}
445
446
if (le -> type == le_db || le -> type == le_pdb ) {
446
447
info = (dba_info * )(le -> ptr );
447
- if (! strcmp ( info -> path , path )) {
448
+ if (zend_string_equals ( path , info -> path )) {
448
449
return (dba_info * )(le -> ptr );
449
450
}
450
451
}
@@ -454,6 +455,20 @@ static dba_info *php_dba_find(const char* path)
454
455
}
455
456
/* }}} */
456
457
458
+ static zend_always_inline zend_string * php_dba_zend_string_dup_safe (zend_string * s , bool persistent )
459
+ {
460
+ if (ZSTR_IS_INTERNED (s ) && !persistent ) {
461
+ return s ;
462
+ } else {
463
+ zend_string * duplicated_str = zend_string_init (ZSTR_VAL (s ), ZSTR_LEN (s ), persistent );
464
+ if (persistent ) {
465
+ GC_MAKE_PERSISTENT_LOCAL (duplicated_str );
466
+ }
467
+ return duplicated_str ;
468
+ }
469
+ }
470
+
471
+
457
472
#define FREE_PERSISTENT_RESOURCE_KEY () if (persistent_resource_key) {zend_string_release_ex(persistent_resource_key, false);}
458
473
459
474
/* {{{ php_dba_open */
@@ -467,7 +482,6 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
467
482
const char * file_mode ;
468
483
const char * lock_file_mode = NULL ;
469
484
int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0 ;
470
- zend_string * opened_path = NULL ;
471
485
char * lock_name ;
472
486
#ifdef PHP_WIN32
473
487
bool restarted = 0 ;
@@ -724,7 +738,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
724
738
725
739
info = pemalloc (sizeof (dba_info ), persistent );
726
740
memset (info , 0 , sizeof (dba_info ));
727
- info -> path = pestrdup ( ZSTR_VAL ( path ) , persistent );
741
+ info -> path = php_dba_zend_string_dup_safe ( path , persistent );
728
742
info -> mode = modenr ;
729
743
info -> file_permission = permission ;
730
744
info -> map_size = map_size ;
@@ -753,8 +767,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
753
767
if (is_db_lock ) {
754
768
lock_name = ZSTR_VAL (path );
755
769
} else {
756
- spprintf (& lock_name , 0 , "%s.lck" , info -> path );
770
+ spprintf (& lock_name , 0 , "%s.lck" , ZSTR_VAL ( info -> path ) );
757
771
if (!strcmp (file_mode , "r" )) {
772
+ zend_string * opened_path = NULL ;
758
773
/* when in read only mode try to use existing .lck file first */
759
774
/* do not log errors for .lck file while in read only mode on .lck file */
760
775
lock_file_mode = "rb" ;
@@ -769,13 +784,17 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
769
784
}
770
785
}
771
786
if (!info -> lock .fp ) {
787
+ zend_string * opened_path = NULL ;
772
788
info -> lock .fp = php_stream_open_wrapper (lock_name , lock_file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , & opened_path );
773
789
if (info -> lock .fp ) {
774
790
if (is_db_lock ) {
791
+ ZEND_ASSERT (opened_path );
775
792
/* replace the path info with the real path of the opened file */
776
- pefree (info -> path , persistent );
777
- info -> path = pestrndup ( ZSTR_VAL ( opened_path ), ZSTR_LEN ( opened_path ) , persistent );
793
+ zend_string_release (info -> path );
794
+ info -> path = php_dba_zend_string_dup_safe ( opened_path , persistent );
778
795
}
796
+ }
797
+ if (opened_path ) {
779
798
zend_string_release_ex (opened_path , 0 );
780
799
}
781
800
}
@@ -801,7 +820,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
801
820
if (info -> lock .fp && is_db_lock ) {
802
821
info -> fp = info -> lock .fp ; /* use the same stream for locking and database access */
803
822
} else {
804
- info -> fp = php_stream_open_wrapper (info -> path , file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , NULL );
823
+ info -> fp = php_stream_open_wrapper (ZSTR_VAL ( info -> path ) , file_mode , STREAM_MUST_SEEK |REPORT_ERRORS |IGNORE_PATH |persistent_flag , NULL );
805
824
}
806
825
if (!info -> fp ) {
807
826
dba_close (info );
@@ -1207,7 +1226,7 @@ PHP_FUNCTION(dba_list)
1207
1226
}
1208
1227
if (le -> type == le_db || le -> type == le_pdb ) {
1209
1228
info = (dba_info * )(le -> ptr );
1210
- add_index_string (return_value , i , info -> path );
1229
+ add_index_str (return_value , i , zend_string_copy ( info -> path ) );
1211
1230
}
1212
1231
}
1213
1232
}
0 commit comments