@@ -281,43 +281,22 @@ typedef struct _php_userstream_data php_userstream_data_t;
281
281
282
282
}}} **/
283
283
284
- static php_stream * user_wrapper_opener ( php_stream_wrapper * wrapper , char * filename , char * mode , int options , char * * opened_path , php_stream_context * context STREAMS_DC TSRMLS_DC )
284
+ static zval * user_stream_create_object ( struct php_user_stream_wrapper * uwrap , php_stream_context * context TSRMLS_DC )
285
285
{
286
- struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper * )wrapper -> abstract ;
287
- php_userstream_data_t * us ;
288
- zval * zfilename , * zmode , * zopened , * zoptions , * zretval = NULL , * zfuncname ;
289
- zval * * args [4 ];
290
- int call_result ;
291
- php_stream * stream = NULL ;
292
- zend_bool old_in_user_include ;
293
-
294
- /* Try to catch bad usage without preventing flexibility */
295
- if (FG (user_stream_current_filename ) != NULL && strcmp (filename , FG (user_stream_current_filename )) == 0 ) {
296
- php_stream_wrapper_log_error (wrapper , options TSRMLS_CC , "infinite recursion prevented" );
297
- return NULL ;
298
- }
299
- FG (user_stream_current_filename ) = filename ;
286
+ zval * object ;
287
+ /* create an instance of our class */
288
+ ALLOC_ZVAL (object );
289
+ object_init_ex (object , uwrap -> ce );
290
+ Z_SET_REFCOUNT_P (object , 1 );
291
+ Z_SET_ISREF_P (object );
300
292
301
- /* if the user stream was registered as local and we are in include context,
302
- we add allow_url_include restrictions to allow_url_fopen ones */
303
- /* we need only is_url == 0 here since if is_url == 1 and remote wrappers
304
- were restricted we wouldn't get here */
305
- old_in_user_include = PG (in_user_include );
306
- if (uwrap -> wrapper .is_url == 0 &&
307
- (options & STREAM_OPEN_FOR_INCLUDE ) &&
308
- !PG (allow_url_include )) {
309
- PG (in_user_include ) = 1 ;
293
+ if (context ) {
294
+ add_property_resource (object , "context" , context -> rsrc_id );
295
+ zend_list_addref (context -> rsrc_id );
296
+ } else {
297
+ add_property_null (object , "context" );
310
298
}
311
299
312
- us = emalloc (sizeof (* us ));
313
- us -> wrapper = uwrap ;
314
-
315
- /* create an instance of our class */
316
- ALLOC_ZVAL (us -> object );
317
- object_init_ex (us -> object , uwrap -> ce );
318
- Z_SET_REFCOUNT_P (us -> object , 1 );
319
- Z_SET_ISREF_P (us -> object );
320
-
321
300
if (uwrap -> ce -> constructor ) {
322
301
zend_fcall_info fci ;
323
302
zend_fcall_info_cache fcc ;
@@ -327,7 +306,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena
327
306
fci .function_table = & uwrap -> ce -> function_table ;
328
307
fci .function_name = NULL ;
329
308
fci .symbol_table = NULL ;
330
- fci .object_ptr = us -> object ;
309
+ fci .object_ptr = object ;
331
310
fci .retval_ptr_ptr = & retval_ptr ;
332
311
fci .param_count = 0 ;
333
312
fci .params = NULL ;
@@ -336,29 +315,60 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena
336
315
fcc .initialized = 1 ;
337
316
fcc .function_handler = uwrap -> ce -> constructor ;
338
317
fcc .calling_scope = EG (scope );
339
- fcc .called_scope = Z_OBJCE_P (us -> object );
340
- fcc .object_ptr = us -> object ;
318
+ fcc .called_scope = Z_OBJCE_P (object );
319
+ fcc .object_ptr = object ;
341
320
342
321
if (zend_call_function (& fci , & fcc TSRMLS_CC ) == FAILURE ) {
343
322
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Could not execute %s::%s()" , uwrap -> ce -> name , uwrap -> ce -> constructor -> common .function_name );
344
- zval_dtor (us -> object );
345
- FREE_ZVAL (us -> object );
346
- efree (us );
347
- FG (user_stream_current_filename ) = NULL ;
348
- PG (in_user_include ) = old_in_user_include ;
323
+ zval_dtor (object );
324
+ FREE_ZVAL (object );
349
325
return NULL ;
350
326
} else {
351
327
if (retval_ptr ) {
352
328
zval_ptr_dtor (& retval_ptr );
353
329
}
354
330
}
355
331
}
332
+ return object ;
333
+ }
356
334
357
- if (context ) {
358
- add_property_resource (us -> object , "context" , context -> rsrc_id );
359
- zend_list_addref (context -> rsrc_id );
360
- } else {
361
- add_property_null (us -> object , "context" );
335
+ static php_stream * user_wrapper_opener (php_stream_wrapper * wrapper , char * filename , char * mode , int options , char * * opened_path , php_stream_context * context STREAMS_DC TSRMLS_DC )
336
+ {
337
+ struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper * )wrapper -> abstract ;
338
+ php_userstream_data_t * us ;
339
+ zval * zfilename , * zmode , * zopened , * zoptions , * zretval = NULL , * zfuncname ;
340
+ zval * * args [4 ];
341
+ int call_result ;
342
+ php_stream * stream = NULL ;
343
+ zend_bool old_in_user_include ;
344
+
345
+ /* Try to catch bad usage without preventing flexibility */
346
+ if (FG (user_stream_current_filename ) != NULL && strcmp (filename , FG (user_stream_current_filename )) == 0 ) {
347
+ php_stream_wrapper_log_error (wrapper , options TSRMLS_CC , "infinite recursion prevented" );
348
+ return NULL ;
349
+ }
350
+ FG (user_stream_current_filename ) = filename ;
351
+
352
+ /* if the user stream was registered as local and we are in include context,
353
+ we add allow_url_include restrictions to allow_url_fopen ones */
354
+ /* we need only is_url == 0 here since if is_url == 1 and remote wrappers
355
+ were restricted we wouldn't get here */
356
+ old_in_user_include = PG (in_user_include );
357
+ if (uwrap -> wrapper .is_url == 0 &&
358
+ (options & STREAM_OPEN_FOR_INCLUDE ) &&
359
+ !PG (allow_url_include )) {
360
+ PG (in_user_include ) = 1 ;
361
+ }
362
+
363
+ us = emalloc (sizeof (* us ));
364
+ us -> wrapper = uwrap ;
365
+
366
+ us -> object = user_stream_create_object (uwrap , context TSRMLS_CC );
367
+ if (us -> object == NULL ) {
368
+ FG (user_stream_current_filename ) = NULL ;
369
+ PG (in_user_include ) = old_in_user_include ;
370
+ efree (us );
371
+ return NULL ;
362
372
}
363
373
364
374
/* call it's stream_open method - set up params first */
@@ -447,17 +457,11 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filen
447
457
us = emalloc (sizeof (* us ));
448
458
us -> wrapper = uwrap ;
449
459
450
- /* create an instance of our class */
451
- ALLOC_ZVAL (us -> object );
452
- object_init_ex (us -> object , uwrap -> ce );
453
- Z_SET_REFCOUNT_P (us -> object , 1 );
454
- Z_SET_ISREF_P (us -> object );
455
-
456
- if (context ) {
457
- add_property_resource (us -> object , "context" , context -> rsrc_id );
458
- zend_list_addref (context -> rsrc_id );
459
- } else {
460
- add_property_null (us -> object , "context" );
460
+ us -> object = user_stream_create_object (uwrap , context TSRMLS_CC );
461
+ if (us == NULL ) {
462
+ FG (user_stream_current_filename ) = NULL ;
463
+ efree (us );
464
+ return NULL ;
461
465
}
462
466
463
467
/* call it's dir_open method - set up params first */
@@ -1157,16 +1161,9 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio
1157
1161
int ret = 0 ;
1158
1162
1159
1163
/* create an instance of our class */
1160
- ALLOC_ZVAL (object );
1161
- object_init_ex (object , uwrap -> ce );
1162
- Z_SET_REFCOUNT_P (object , 1 );
1163
- Z_SET_ISREF_P (object );
1164
-
1165
- if (context ) {
1166
- add_property_resource (object , "context" , context -> rsrc_id );
1167
- zend_list_addref (context -> rsrc_id );
1168
- } else {
1169
- add_property_null (object , "context" );
1164
+ object = user_stream_create_object (uwrap , context TSRMLS_CC );
1165
+ if (object == NULL ) {
1166
+ return ret ;
1170
1167
}
1171
1168
1172
1169
/* call the unlink method */
@@ -1211,16 +1208,9 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char
1211
1208
int ret = 0 ;
1212
1209
1213
1210
/* create an instance of our class */
1214
- ALLOC_ZVAL (object );
1215
- object_init_ex (object , uwrap -> ce );
1216
- Z_SET_REFCOUNT_P (object , 1 );
1217
- Z_SET_ISREF_P (object );
1218
-
1219
- if (context ) {
1220
- add_property_resource (object , "context" , context -> rsrc_id );
1221
- zend_list_addref (context -> rsrc_id );
1222
- } else {
1223
- add_property_null (object , "context" );
1211
+ object = user_stream_create_object (uwrap , context TSRMLS_CC );
1212
+ if (object == NULL ) {
1213
+ return ret ;
1224
1214
}
1225
1215
1226
1216
/* call the rename method */
@@ -1270,16 +1260,9 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode,
1270
1260
int ret = 0 ;
1271
1261
1272
1262
/* create an instance of our class */
1273
- ALLOC_ZVAL (object );
1274
- object_init_ex (object , uwrap -> ce );
1275
- Z_SET_REFCOUNT_P (object , 1 );
1276
- Z_SET_ISREF_P (object );
1277
-
1278
- if (context ) {
1279
- add_property_resource (object , "context" , context -> rsrc_id );
1280
- zend_list_addref (context -> rsrc_id );
1281
- } else {
1282
- add_property_null (object , "context" );
1263
+ object = user_stream_create_object (uwrap , context TSRMLS_CC );
1264
+ if (object == NULL ) {
1265
+ return ret ;
1283
1266
}
1284
1267
1285
1268
/* call the mkdir method */
@@ -1335,16 +1318,9 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int option
1335
1318
int ret = 0 ;
1336
1319
1337
1320
/* create an instance of our class */
1338
- ALLOC_ZVAL (object );
1339
- object_init_ex (object , uwrap -> ce );
1340
- Z_SET_REFCOUNT_P (object , 1 );
1341
- Z_SET_ISREF_P (object );
1342
-
1343
- if (context ) {
1344
- add_property_resource (object , "context" , context -> rsrc_id );
1345
- zend_list_addref (context -> rsrc_id );
1346
- } else {
1347
- add_property_null (object , "context" );
1321
+ object = user_stream_create_object (uwrap , context TSRMLS_CC );
1322
+ if (object == NULL ) {
1323
+ return ret ;
1348
1324
}
1349
1325
1350
1326
/* call the rmdir method */
@@ -1420,16 +1396,10 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int opt
1420
1396
}
1421
1397
1422
1398
/* create an instance of our class */
1423
- ALLOC_ZVAL (object );
1424
- object_init_ex (object , uwrap -> ce );
1425
- Z_SET_REFCOUNT_P (object , 1 );
1426
- Z_SET_ISREF_P (object );
1427
-
1428
- if (context ) {
1429
- add_property_resource (object , "context" , context -> rsrc_id );
1430
- zend_list_addref (context -> rsrc_id );
1431
- } else {
1432
- add_property_null (object , "context" );
1399
+ object = user_stream_create_object (uwrap , context TSRMLS_CC );
1400
+ if (object == NULL ) {
1401
+ zval_ptr_dtor (& zvalue );
1402
+ return ret ;
1433
1403
}
1434
1404
1435
1405
/* call the mkdir method */
@@ -1484,16 +1454,9 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int fla
1484
1454
int ret = -1 ;
1485
1455
1486
1456
/* create an instance of our class */
1487
- ALLOC_ZVAL (object );
1488
- object_init_ex (object , uwrap -> ce );
1489
- Z_SET_REFCOUNT_P (object , 1 );
1490
- Z_SET_ISREF_P (object );
1491
-
1492
- if (context ) {
1493
- add_property_resource (object , "context" , context -> rsrc_id );
1494
- zend_list_addref (context -> rsrc_id );
1495
- } else {
1496
- add_property_null (object , "context" );
1457
+ object = user_stream_create_object (uwrap , context TSRMLS_CC );
1458
+ if (object == NULL ) {
1459
+ return ret ;
1497
1460
}
1498
1461
1499
1462
/* call it's stat_url method - set up params first */
0 commit comments