@@ -199,15 +199,16 @@ PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, size_
199
199
return intern -> _path ;
200
200
} /* }}} */
201
201
202
- static inline void spl_filesystem_object_get_file_name (spl_filesystem_object * intern ) /* {{{ */
202
+ static inline int spl_filesystem_object_get_file_name (spl_filesystem_object * intern ) /* {{{ */
203
203
{
204
204
char slash = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
205
205
206
206
switch (intern -> type ) {
207
207
case SPL_FS_INFO :
208
208
case SPL_FS_FILE :
209
209
if (!intern -> file_name ) {
210
- php_error_docref (NULL , E_ERROR , "Object not initialized" );
210
+ zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Object not initialized" );
211
+ return FAILURE ;
211
212
}
212
213
break ;
213
214
case SPL_FS_DIR :
@@ -228,6 +229,7 @@ static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *in
228
229
}
229
230
break ;
230
231
}
232
+ return SUCCESS ;
231
233
} /* }}} */
232
234
233
235
static int spl_filesystem_dir_read (spl_filesystem_object * intern ) /* {{{ */
@@ -479,16 +481,13 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
479
481
zval arg1 , arg2 ;
480
482
zend_error_handling error_handling ;
481
483
482
- zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
483
-
484
484
switch (source -> type ) {
485
485
case SPL_FS_INFO :
486
486
case SPL_FS_FILE :
487
487
break ;
488
488
case SPL_FS_DIR :
489
489
if (!source -> u .dir .entry .d_name [0 ]) {
490
490
zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Could not open file" );
491
- zend_restore_error_handling (& error_handling );
492
491
return NULL ;
493
492
}
494
493
}
@@ -498,13 +497,16 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
498
497
ce = ce ? ce : source -> info_class ;
499
498
500
499
if (UNEXPECTED (zend_update_class_constants (ce ) != SUCCESS )) {
501
- break ;
500
+ return NULL ;
502
501
}
503
502
504
503
intern = spl_filesystem_from_obj (spl_filesystem_object_new_ex (ce ));
505
504
RETVAL_OBJ (& intern -> std );
506
505
507
- spl_filesystem_object_get_file_name (source );
506
+ if (spl_filesystem_object_get_file_name (source ) != SUCCESS ) {
507
+ return NULL ;
508
+ }
509
+
508
510
if (ce -> constructor -> common .scope != spl_ce_SplFileInfo ) {
509
511
ZVAL_STRINGL (& arg1 , source -> file_name , source -> file_name_len );
510
512
zend_call_method_with_1_params (Z_OBJ_P (return_value ), ce , & ce -> constructor , "__construct" , NULL , & arg1 );
@@ -521,7 +523,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
521
523
ce = ce ? ce : source -> file_class ;
522
524
523
525
if (UNEXPECTED (zend_update_class_constants (ce ) != SUCCESS )) {
524
- break ;
526
+ return NULL ;
525
527
}
526
528
527
529
char * open_mode = "r" ;
@@ -531,15 +533,15 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
531
533
if (zend_parse_parameters (num_args , "|sbr" ,
532
534
& open_mode , & open_mode_len , & use_include_path , & resource ) == FAILURE
533
535
) {
534
- zend_restore_error_handling (& error_handling );
535
536
return NULL ;
536
537
}
537
538
538
539
intern = spl_filesystem_from_obj (spl_filesystem_object_new_ex (ce ));
539
-
540
540
RETVAL_OBJ (& intern -> std );
541
541
542
- spl_filesystem_object_get_file_name (source );
542
+ if (spl_filesystem_object_get_file_name (source ) != SUCCESS ) {
543
+ return NULL ;
544
+ }
543
545
544
546
if (ce -> constructor -> common .scope != spl_ce_SplFileObject ) {
545
547
ZVAL_STRINGL (& arg1 , source -> file_name , source -> file_name_len );
@@ -557,21 +559,21 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
557
559
intern -> u .file .open_mode_len = open_mode_len ;
558
560
intern -> u .file .zcontext = resource ;
559
561
562
+ zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
560
563
if (spl_filesystem_file_open (intern , use_include_path , 0 ) == FAILURE ) {
561
564
zend_restore_error_handling (& error_handling );
562
565
zval_ptr_dtor (return_value );
563
566
ZVAL_NULL (return_value );
564
567
return NULL ;
565
568
}
569
+ zend_restore_error_handling (& error_handling );
566
570
}
567
571
break ;
568
572
}
569
573
case SPL_FS_DIR :
570
- zend_restore_error_handling (& error_handling );
571
574
zend_throw_exception_ex (spl_ce_RuntimeException , 0 , "Operation not supported" );
572
575
return NULL ;
573
576
}
574
- zend_restore_error_handling (& error_handling );
575
577
return NULL ;
576
578
} /* }}} */
577
579
@@ -1060,7 +1062,9 @@ PHP_METHOD(FilesystemIterator, key)
1060
1062
if (SPL_FILE_DIR_KEY (intern , SPL_FILE_DIR_KEY_AS_FILENAME )) {
1061
1063
RETURN_STRING (intern -> u .dir .entry .d_name );
1062
1064
} else {
1063
- spl_filesystem_object_get_file_name (intern );
1065
+ if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1066
+ RETURN_THROWS ();
1067
+ }
1064
1068
RETURN_STRINGL (intern -> file_name , intern -> file_name_len );
1065
1069
}
1066
1070
}
@@ -1076,10 +1080,14 @@ PHP_METHOD(FilesystemIterator, current)
1076
1080
}
1077
1081
1078
1082
if (SPL_FILE_DIR_CURRENT (intern , SPL_FILE_DIR_CURRENT_AS_PATHNAME )) {
1079
- spl_filesystem_object_get_file_name (intern );
1083
+ if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1084
+ RETURN_THROWS ();
1085
+ }
1080
1086
RETURN_STRINGL (intern -> file_name , intern -> file_name_len );
1081
1087
} else if (SPL_FILE_DIR_CURRENT (intern , SPL_FILE_DIR_CURRENT_AS_FILEINFO )) {
1082
- spl_filesystem_object_get_file_name (intern );
1088
+ if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1089
+ RETURN_THROWS ();
1090
+ }
1083
1091
spl_filesystem_object_create_type (0 , intern , SPL_FS_INFO , NULL , return_value );
1084
1092
} else {
1085
1093
RETURN_OBJ_COPY (Z_OBJ_P (ZEND_THIS ));
@@ -1131,9 +1139,10 @@ PHP_METHOD(SplFileInfo, func_name) \
1131
1139
if (zend_parse_parameters_none() == FAILURE) { \
1132
1140
RETURN_THROWS(); \
1133
1141
} \
1134
- \
1142
+ if (spl_filesystem_object_get_file_name(intern) != SUCCESS) { \
1143
+ RETURN_THROWS(); \
1144
+ } \
1135
1145
zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);\
1136
- spl_filesystem_object_get_file_name(intern); \
1137
1146
php_stat(intern->file_name, intern->file_name_len, func_num, return_value); \
1138
1147
zend_restore_error_handling(&error_handling); \
1139
1148
}
@@ -1214,7 +1223,9 @@ PHP_METHOD(SplFileInfo, getLinkTarget)
1214
1223
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
1215
1224
1216
1225
if (intern -> file_name == NULL ) {
1217
- spl_filesystem_object_get_file_name (intern );
1226
+ if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1227
+ RETURN_THROWS ();
1228
+ }
1218
1229
}
1219
1230
#if defined(PHP_WIN32 ) || defined(HAVE_SYMLINK )
1220
1231
if (intern -> file_name == NULL ) {
@@ -1263,7 +1274,9 @@ PHP_METHOD(SplFileInfo, getRealPath)
1263
1274
zend_replace_error_handling (EH_THROW , spl_ce_RuntimeException , & error_handling );
1264
1275
1265
1276
if (intern -> type == SPL_FS_DIR && !intern -> file_name && intern -> u .dir .entry .d_name [0 ]) {
1266
- spl_filesystem_object_get_file_name (intern );
1277
+ if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1278
+ RETURN_THROWS ();
1279
+ }
1267
1280
}
1268
1281
1269
1282
if (intern -> orig_path ) {
@@ -1445,7 +1458,9 @@ PHP_METHOD(RecursiveDirectoryIterator, hasChildren)
1445
1458
if (spl_filesystem_is_invalid_or_dot (intern -> u .dir .entry .d_name )) {
1446
1459
RETURN_FALSE ;
1447
1460
} else {
1448
- spl_filesystem_object_get_file_name (intern );
1461
+ if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1462
+ RETURN_THROWS ();
1463
+ }
1449
1464
if (!allow_links && !(intern -> flags & SPL_FILE_DIR_FOLLOW_SYMLINKS )) {
1450
1465
php_stat (intern -> file_name , intern -> file_name_len , FS_IS_LINK , return_value );
1451
1466
if (zend_is_true (return_value )) {
@@ -1469,7 +1484,9 @@ PHP_METHOD(RecursiveDirectoryIterator, getChildren)
1469
1484
RETURN_THROWS ();
1470
1485
}
1471
1486
1472
- spl_filesystem_object_get_file_name (intern );
1487
+ if (spl_filesystem_object_get_file_name (intern ) != SUCCESS ) {
1488
+ RETURN_THROWS ();
1489
+ }
1473
1490
1474
1491
ZVAL_LONG (& zflags , intern -> flags );
1475
1492
ZVAL_STRINGL (& zpath , intern -> file_name , intern -> file_name_len );
@@ -1698,13 +1715,17 @@ static zval *spl_filesystem_tree_it_current_data(zend_object_iterator *iter)
1698
1715
1699
1716
if (SPL_FILE_DIR_CURRENT (object , SPL_FILE_DIR_CURRENT_AS_PATHNAME )) {
1700
1717
if (Z_ISUNDEF (iterator -> current )) {
1701
- spl_filesystem_object_get_file_name (object );
1718
+ if (spl_filesystem_object_get_file_name (object ) != SUCCESS ) {
1719
+ return NULL ;
1720
+ }
1702
1721
ZVAL_STRINGL (& iterator -> current , object -> file_name , object -> file_name_len );
1703
1722
}
1704
1723
return & iterator -> current ;
1705
1724
} else if (SPL_FILE_DIR_CURRENT (object , SPL_FILE_DIR_CURRENT_AS_FILEINFO )) {
1706
1725
if (Z_ISUNDEF (iterator -> current )) {
1707
- spl_filesystem_object_get_file_name (object );
1726
+ if (spl_filesystem_object_get_file_name (object ) != SUCCESS ) {
1727
+ return NULL ;
1728
+ }
1708
1729
spl_filesystem_object_create_type (0 , object , SPL_FS_INFO , NULL , & iterator -> current );
1709
1730
}
1710
1731
return & iterator -> current ;
@@ -1722,7 +1743,9 @@ static void spl_filesystem_tree_it_current_key(zend_object_iterator *iter, zval
1722
1743
if (SPL_FILE_DIR_KEY (object , SPL_FILE_DIR_KEY_AS_FILENAME )) {
1723
1744
ZVAL_STRING (key , object -> u .dir .entry .d_name );
1724
1745
} else {
1725
- spl_filesystem_object_get_file_name (object );
1746
+ if (spl_filesystem_object_get_file_name (object ) != SUCCESS ) {
1747
+ return ;
1748
+ }
1726
1749
ZVAL_STRINGL (key , object -> file_name , object -> file_name_len );
1727
1750
}
1728
1751
}
0 commit comments