Browse Source

Use zend_string* instead of char* for opened_patch handling. Avoid reallocations and improve string reuse.

pull/1136/head
Dmitry Stogov 12 years ago
parent
commit
2fa8d67a5c
  1. 10
      Zend/zend.c
  2. 8
      Zend/zend.h
  3. 5430
      Zend/zend_language_scanner.c
  4. 14
      Zend/zend_language_scanner.l
  5. 2
      Zend/zend_language_scanner_defs.h
  6. 2
      Zend/zend_stream.c
  7. 2
      Zend/zend_stream.h
  8. 16
      Zend/zend_vm_def.h
  9. 48
      Zend/zend_vm_execute.h
  10. 18
      ext/bz2/bz2.c
  11. 2
      ext/bz2/php_bz2.h
  12. 22
      ext/dba/dba.c
  13. 6
      ext/gd/gd.c
  14. 75
      ext/opcache/ZendAccelerator.c
  15. 19
      ext/opcache/zend_accelerator_module.c
  16. 2
      ext/phar/dirstream.c
  17. 2
      ext/phar/dirstream.h
  18. 33
      ext/phar/func_interceptors.c
  19. 37
      ext/phar/phar.c
  20. 4
      ext/phar/phar_internal.h
  21. 19
      ext/phar/phar_object.c
  22. 10
      ext/phar/stream.c
  23. 2
      ext/phar/stream.h
  24. 17
      ext/phar/util.c
  25. 4
      ext/spl/php_spl.c
  26. 6
      ext/standard/file.c
  27. 6
      ext/standard/ftp_fopen_wrapper.c
  28. 4
      ext/standard/http_fopen_wrapper.c
  29. 3
      ext/standard/php_fopen_wrapper.c
  30. 4
      ext/standard/php_fopen_wrappers.h
  31. 8
      ext/standard/streamsfuncs.c
  32. 2
      ext/zip/php_zip.h
  33. 4
      ext/zip/zip_stream.c
  34. 2
      ext/zlib/php_zlib.h
  35. 2
      ext/zlib/zlib_fopen_wrapper.c
  36. 29
      main/fopen_wrappers.c
  37. 4
      main/fopen_wrappers.h
  38. 11
      main/main.c
  39. 16
      main/php_ini.c
  40. 20
      main/php_open_temporary_file.c
  41. 6
      main/php_open_temporary_file.h
  42. 6
      main/php_streams.h
  43. 35
      main/rfc1867.c
  44. 4
      main/streams/cast.c
  45. 4
      main/streams/glob_wrapper.c
  46. 2
      main/streams/memory.c
  47. 8
      main/streams/php_stream_plain_wrapper.h
  48. 54
      main/streams/plain_wrapper.c
  49. 16
      main/streams/streams.c
  50. 10
      main/streams/userspace.c

10
Zend/zend.c

@ -48,7 +48,7 @@
ZEND_API zend_class_entry *zend_standard_class_def = NULL;
ZEND_API size_t (*zend_printf)(const char *format, ...);
ZEND_API zend_write_func_t zend_write;
ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
ZEND_API void (*zend_block_interruptions)(void);
ZEND_API void (*zend_unblock_interruptions)(void);
@ -57,7 +57,7 @@ ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint
size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len);
ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
void (*zend_on_timeout)(int seconds);
@ -374,10 +374,10 @@ ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int
}
/* }}} */
static FILE *zend_fopen_wrapper(const char *filename, char **opened_path) /* {{{ */
static FILE *zend_fopen_wrapper(const char *filename, zend_string **opened_path) /* {{{ */
{
if (opened_path) {
*opened_path = estrdup(filename);
*opened_path = zend_string_init(filename, strlen(filename), 0);
}
return fopen(filename, "rb");
}
@ -1303,7 +1303,7 @@ ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...) /
op_array = zend_compile_file(file_handle, type);
if (file_handle->opened_path) {
zend_hash_str_add_empty_element(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path));
zend_hash_add_empty_element(&EG(included_files), file_handle->opened_path);
}
zend_destroy_file_handle(file_handle);
if (op_array) {

8
Zend/zend.h

@ -193,7 +193,7 @@ typedef struct _zend_utility_functions {
void (*error_function)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0);
size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
size_t (*write_function)(const char *str, size_t str_length);
FILE *(*fopen_function)(const char *filename, char **opened_path);
FILE *(*fopen_function)(const char *filename, zend_string **opened_path);
void (*message_handler)(zend_long message, const void *data);
void (*block_interruptions)(void);
void (*unblock_interruptions)(void);
@ -204,7 +204,7 @@ typedef struct _zend_utility_functions {
size_t (*vspprintf_function)(char **pbuf, size_t max_len, const char *format, va_list ap);
zend_string *(*vstrpprintf_function)(size_t max_len, const char *format, va_list ap);
char *(*getenv_function)(char *name, size_t name_len);
char *(*resolve_path_function)(const char *filename, int filename_len);
zend_string *(*resolve_path_function)(const char *filename, int filename_len);
} zend_utility_functions;
typedef struct _zend_utility_values {
@ -272,7 +272,7 @@ END_EXTERN_C()
BEGIN_EXTERN_C()
extern ZEND_API size_t (*zend_printf)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
extern ZEND_API zend_write_func_t zend_write;
extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
extern ZEND_API FILE *(*zend_fopen)(const char *filename, zend_string **opened_path);
extern ZEND_API void (*zend_block_interruptions)(void);
extern ZEND_API void (*zend_unblock_interruptions)(void);
extern ZEND_API void (*zend_ticks_function)(int ticks);
@ -282,7 +282,7 @@ extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file
extern size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
extern zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
extern ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len);
extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int filename_len);
ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

5430
Zend/zend_language_scanner.c
File diff suppressed because it is too large
View File

14
Zend/zend_language_scanner.l

@ -482,7 +482,6 @@ ZEND_API int zend_multibyte_set_filter(const zend_encoding *onetime_encoding)
ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
{
const char *file_path = NULL;
char *buf;
size_t size, offset = 0;
zend_string *compiled_filename;
@ -536,12 +535,11 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
BEGIN(INITIAL);
if (file_handle->opened_path) {
file_path = file_handle->opened_path;
compiled_filename = zend_string_copy(file_handle->opened_path);
} else {
file_path = file_handle->filename;
compiled_filename = zend_string_init(file_handle->filename, strlen(file_handle->filename), 0);
}
compiled_filename = zend_string_init(file_path, strlen(file_path), 0);
zend_set_compiled_filename(compiled_filename);
zend_string_release(compiled_filename);
@ -623,7 +621,7 @@ zend_op_array *compile_filename(int type, zval *filename)
zend_file_handle file_handle;
zval tmp;
zend_op_array *retval;
char *opened_path = NULL;
zend_string *opened_path = NULL;
if (Z_TYPE_P(filename) != IS_STRING) {
tmp = *filename;
@ -640,13 +638,13 @@ zend_op_array *compile_filename(int type, zval *filename)
retval = zend_compile_file(&file_handle, type);
if (retval && file_handle.handle.stream.handle) {
if (!file_handle.opened_path) {
file_handle.opened_path = opened_path = estrndup(Z_STRVAL_P(filename), Z_STRLEN_P(filename));
file_handle.opened_path = opened_path = zend_string_copy(Z_STR_P(filename));
}
zend_hash_str_add_empty_element(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path));
zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path);
if (opened_path) {
efree(opened_path);
zend_string_release(opened_path);
}
}
zend_destroy_file_handle(&file_handle);

2
Zend/zend_language_scanner_defs.h

@ -1,4 +1,4 @@
/* Generated by re2c 0.13.7.5 */
/* Generated by re2c 0.13.5 */
#line 3 "Zend/zend_language_scanner_defs.h"
enum YYCONDTYPE {

2
Zend/zend_stream.c

@ -322,7 +322,7 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
break;
}
if (fh->opened_path) {
efree(fh->opened_path);
zend_string_release(fh->opened_path);
fh->opened_path = NULL;
}
if (fh->free_filename && fh->filename) {

2
Zend/zend_stream.h

@ -69,7 +69,7 @@ typedef struct _zend_file_handle {
zend_stream stream;
} handle;
const char *filename;
char *opened_path;
zend_string *opened_path;
zend_stream_type type;
zend_bool free_filename;
} zend_file_handle;

16
Zend/zend_vm_def.h

@ -4589,24 +4589,24 @@ ZEND_VM_HANDLER(73, ZEND_INCLUDE_OR_EVAL, CONST|TMPVAR|CV, ANY)
case ZEND_INCLUDE_ONCE:
case ZEND_REQUIRE_ONCE: {
zend_file_handle file_handle;
char *resolved_path;
zend_string *resolved_path;
resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename));
if (resolved_path) {
failure_retval = zend_hash_str_exists(&EG(included_files), resolved_path, (int)strlen(resolved_path));
failure_retval = zend_hash_exists(&EG(included_files), resolved_path);
} else {
resolved_path = Z_STRVAL_P(inc_filename);
resolved_path = zend_string_copy(Z_STR_P(inc_filename));
}
if (failure_retval) {
/* do nothing, file already included */
} else if (SUCCESS == zend_stream_open(resolved_path, &file_handle)) {
} else if (SUCCESS == zend_stream_open(resolved_path->val, &file_handle)) {
if (!file_handle.opened_path) {
file_handle.opened_path = estrdup(resolved_path);
file_handle.opened_path = zend_string_copy(resolved_path);
}
if (zend_hash_str_add_empty_element(&EG(included_files), file_handle.opened_path, (int)strlen(file_handle.opened_path))) {
if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) {
new_op_array = zend_compile_file(&file_handle, (opline->extended_value==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE));
zend_destroy_file_handle(&file_handle);
} else {
@ -4620,9 +4620,7 @@ ZEND_VM_HANDLER(73, ZEND_INCLUDE_OR_EVAL, CONST|TMPVAR|CV, ANY)
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, Z_STRVAL_P(inc_filename));
}
}
if (resolved_path != Z_STRVAL_P(inc_filename)) {
efree(resolved_path);
}
zend_string_release(resolved_path);
}
break;
case ZEND_INCLUDE:

48
Zend/zend_vm_execute.h

@ -3127,24 +3127,24 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HA
case ZEND_INCLUDE_ONCE:
case ZEND_REQUIRE_ONCE: {
zend_file_handle file_handle;
char *resolved_path;
zend_string *resolved_path;
resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename));
if (resolved_path) {
failure_retval = zend_hash_str_exists(&EG(included_files), resolved_path, (int)strlen(resolved_path));
failure_retval = zend_hash_exists(&EG(included_files), resolved_path);
} else {
resolved_path = Z_STRVAL_P(inc_filename);
resolved_path = zend_string_copy(Z_STR_P(inc_filename));
}
if (failure_retval) {
/* do nothing, file already included */
} else if (SUCCESS == zend_stream_open(resolved_path, &file_handle)) {
} else if (SUCCESS == zend_stream_open(resolved_path->val, &file_handle)) {
if (!file_handle.opened_path) {
file_handle.opened_path = estrdup(resolved_path);
file_handle.opened_path = zend_string_copy(resolved_path);
}
if (zend_hash_str_add_empty_element(&EG(included_files), file_handle.opened_path, (int)strlen(file_handle.opened_path))) {
if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) {
new_op_array = zend_compile_file(&file_handle, (opline->extended_value==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE));
zend_destroy_file_handle(&file_handle);
} else {
@ -3158,9 +3158,7 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HA
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, Z_STRVAL_P(inc_filename));
}
}
if (resolved_path != Z_STRVAL_P(inc_filename)) {
efree(resolved_path);
}
zend_string_release(resolved_path);
}
break;
case ZEND_INCLUDE:
@ -24687,24 +24685,24 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDL
case ZEND_INCLUDE_ONCE:
case ZEND_REQUIRE_ONCE: {
zend_file_handle file_handle;
char *resolved_path;
zend_string *resolved_path;
resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename));
if (resolved_path) {
failure_retval = zend_hash_str_exists(&EG(included_files), resolved_path, (int)strlen(resolved_path));
failure_retval = zend_hash_exists(&EG(included_files), resolved_path);
} else {
resolved_path = Z_STRVAL_P(inc_filename);
resolved_path = zend_string_copy(Z_STR_P(inc_filename));
}
if (failure_retval) {
/* do nothing, file already included */
} else if (SUCCESS == zend_stream_open(resolved_path, &file_handle)) {
} else if (SUCCESS == zend_stream_open(resolved_path->val, &file_handle)) {
if (!file_handle.opened_path) {
file_handle.opened_path = estrdup(resolved_path);
file_handle.opened_path = zend_string_copy(resolved_path);
}
if (zend_hash_str_add_empty_element(&EG(included_files), file_handle.opened_path, (int)strlen(file_handle.opened_path))) {
if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) {
new_op_array = zend_compile_file(&file_handle, (opline->extended_value==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE));
zend_destroy_file_handle(&file_handle);
} else {
@ -24718,9 +24716,7 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDL
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, Z_STRVAL_P(inc_filename));
}
}
if (resolved_path != Z_STRVAL_P(inc_filename)) {
efree(resolved_path);
}
zend_string_release(resolved_path);
}
break;
case ZEND_INCLUDE:
@ -34099,24 +34095,24 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_TMPVAR_HANDLER(ZEND_OPCODE_H
case ZEND_INCLUDE_ONCE:
case ZEND_REQUIRE_ONCE: {
zend_file_handle file_handle;
char *resolved_path;
zend_string *resolved_path;
resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename));
if (resolved_path) {
failure_retval = zend_hash_str_exists(&EG(included_files), resolved_path, (int)strlen(resolved_path));
failure_retval = zend_hash_exists(&EG(included_files), resolved_path);
} else {
resolved_path = Z_STRVAL_P(inc_filename);
resolved_path = zend_string_copy(Z_STR_P(inc_filename));
}
if (failure_retval) {
/* do nothing, file already included */
} else if (SUCCESS == zend_stream_open(resolved_path, &file_handle)) {
} else if (SUCCESS == zend_stream_open(resolved_path->val, &file_handle)) {
if (!file_handle.opened_path) {
file_handle.opened_path = estrdup(resolved_path);
file_handle.opened_path = zend_string_copy(resolved_path);
}
if (zend_hash_str_add_empty_element(&EG(included_files), file_handle.opened_path, (int)strlen(file_handle.opened_path))) {
if (zend_hash_add_empty_element(&EG(included_files), file_handle.opened_path)) {
new_op_array = zend_compile_file(&file_handle, (opline->extended_value==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE));
zend_destroy_file_handle(&file_handle);
} else {
@ -34130,9 +34126,7 @@ static int ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_TMPVAR_HANDLER(ZEND_OPCODE_H
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, Z_STRVAL_P(inc_filename));
}
}
if (resolved_path != Z_STRVAL_P(inc_filename)) {
efree(resolved_path);
}
zend_string_release(resolved_path);
}
break;
case ZEND_INCLUDE:

18
ext/bz2/bz2.c

@ -235,7 +235,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
const char *path,
const char *mode,
int options,
char **opened_path,
zend_string **opened_path,
php_stream_context *context STREAMS_DC)
{
php_stream *retstream = NULL, *stream = NULL;
@ -266,20 +266,8 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
bz_file = BZ2_bzopen(path_copy, mode);
if (opened_path && bz_file) {
#ifdef VIRTUAL_DIR
*opened_path = path_copy;
path_copy = NULL;
#else
*opened_path = estrdup(path_copy);
#endif
}
#ifdef VIRTUAL_DIR
if (path_copy) {
efree(path_copy);
*opened_path = zend_string_init(path_copy, strlen(path_copy), 0);
}
#endif
path_copy = NULL;
if (bz_file == NULL) {
/* that didn't work, so try and get something from the network/wrapper */
@ -296,7 +284,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
* failed.
*/
if (opened_path && !bz_file && mode[0] == 'w') {
VCWD_UNLINK(*opened_path);
VCWD_UNLINK((*opened_path)->val);
}
}

2
ext/bz2/php_bz2.h

@ -47,7 +47,7 @@ extern zend_module_entry bz2_module_entry;
# define PHP_BZ2_API
#endif
PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, const char *mode, php_stream *innerstream STREAMS_DC);
#define php_stream_bz2open_from_BZFILE(bz, mode, innerstream) _php_stream_bz2open_from_BZFILE((bz), (mode), (innerstream) STREAMS_CC)

22
ext/dba/dba.c

@ -627,7 +627,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
char *file_mode;
char mode[4], *pmode, *lock_file_mode = NULL;
int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0;
char *opened_path = NULL;
zend_string *opened_path = NULL;
char *lock_name;
if (ac < 2) {
@ -853,13 +853,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
/* when not in read mode or failed to open .lck file read only. now try again in create(write) mode and log errors */
lock_file_mode = "a+b";
} else {
if (!persistent) {
info->lock.name = opened_path;
} else {
if (opened_path) {
info->lock.name = pestrdup(opened_path, persistent);
efree(opened_path);
}
if (opened_path) {
info->lock.name = pestrndup(opened_path->val, opened_path->len, persistent);
zend_string_release(opened_path);
}
}
}
@ -869,15 +865,11 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (lock_dbf) {
/* replace the path info with the real path of the opened file */
pefree(info->path, persistent);
info->path = pestrdup(opened_path, persistent);
info->path = pestrndup(opened_path->val, opened_path->len, persistent);
}
/* now store the name of the lock */
if (!persistent) {
info->lock.name = opened_path;
} else {
info->lock.name = pestrdup(opened_path, persistent);
efree(opened_path);
}
info->lock.name = pestrdup(opened_path->val, opened_path->len, persistent);
zend_string_release(opened_path);
}
}
if (!lock_dbf) {

6
ext/gd/gd.c

@ -2686,7 +2686,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
int b;
FILE *tmp;
char buf[4096];
char *path;
zend_string *path;
tmp = php_open_temporary_file(NULL, NULL, &path);
if (tmp == NULL) {
@ -2745,8 +2745,8 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
}
fclose(tmp);
VCWD_UNLINK((const char *)path); /* make sure that the temporary file is removed */
efree(path);
VCWD_UNLINK((const char *)path->val); /* make sure that the temporary file is removed */
zend_string_release(path);
}
RETURN_TRUE;
}

75
ext/opcache/ZendAccelerator.c

@ -105,7 +105,7 @@ char *zps_api_failure_reason = NULL;
static zend_op_array *(*accelerator_orig_compile_file)(zend_file_handle *file_handle, int type);
static int (*accelerator_orig_zend_stream_open_function)(const char *filename, zend_file_handle *handle );
static char *(*accelerator_orig_zend_resolve_path)(const char *filename, int filename_len);
static zend_string *(*accelerator_orig_zend_resolve_path)(const char *filename, int filename_len);
static void (*orig_chdir)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL;
@ -765,25 +765,23 @@ static accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle
break;
case ZEND_HANDLE_FILENAME:
case ZEND_HANDLE_MAPPED:
{
char *file_path = file_handle->opened_path;
if (file_handle->opened_path) {
char *file_path = file_handle->opened_path->val;
if (file_path) {
if (is_stream_path(file_path)) {
if (zend_get_stream_timestamp(file_path, &statbuf) == SUCCESS) {
break;
}
}
if (VCWD_STAT(file_path, &statbuf) != -1) {
if (is_stream_path(file_path)) {
if (zend_get_stream_timestamp(file_path, &statbuf) == SUCCESS) {
break;
}
}
if (zend_get_stream_timestamp(file_handle->filename, &statbuf) != SUCCESS) {
return 0;
if (VCWD_STAT(file_path, &statbuf) != -1) {
break;
}
break;
}
if (zend_get_stream_timestamp(file_handle->filename, &statbuf) != SUCCESS) {
return 0;
}
break;
case ZEND_HANDLE_STREAM:
{
php_stream *stream = (php_stream *)file_handle->handle.stream.handle;
@ -825,20 +823,25 @@ static accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle
static inline int do_validate_timestamps(zend_persistent_script *persistent_script, zend_file_handle *file_handle)
{
zend_file_handle ps_handle;
char *full_path_ptr = NULL;
zend_string *full_path_ptr = NULL;
/** check that the persistent script is indeed the same file we cached
* (if part of the path is a symlink than it possible that the user will change it)
* See bug #15140
*/
if (file_handle->opened_path) {
if (strcmp(persistent_script->full_path->val, file_handle->opened_path) != 0) {
if (persistent_script->full_path != file_handle->opened_path &&
(persistent_script->full_path->len != file_handle->opened_path->len ||
memcmp(persistent_script->full_path->val, file_handle->opened_path->val, file_handle->opened_path->len) != 0)) {
return FAILURE;
}
} else {
full_path_ptr = accelerator_orig_zend_resolve_path(file_handle->filename, strlen(file_handle->filename));
if (full_path_ptr && strcmp(persistent_script->full_path->val, full_path_ptr) != 0) {
efree(full_path_ptr);
if (full_path_ptr &&
persistent_script->full_path != full_path_ptr &&
(persistent_script->full_path->len != full_path_ptr->len ||
memcmp(persistent_script->full_path->val, full_path_ptr->val, full_path_ptr->len) != 0)) {
zend_string_release(full_path_ptr);
return FAILURE;
}
file_handle->opened_path = full_path_ptr;
@ -846,7 +849,7 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri
if (persistent_script->timestamp == 0) {
if (full_path_ptr) {
efree(full_path_ptr);
zend_string_release(full_path_ptr);
file_handle->opened_path = NULL;
}
return FAILURE;
@ -854,19 +857,19 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri
if (zend_get_file_handle_timestamp(file_handle, NULL) == persistent_script->timestamp) {
if (full_path_ptr) {
efree(full_path_ptr);
zend_string_release(full_path_ptr);
file_handle->opened_path = NULL;
}
return SUCCESS;
}
if (full_path_ptr) {
efree(full_path_ptr);
zend_string_release(full_path_ptr);
file_handle->opened_path = NULL;
}
ps_handle.type = ZEND_HANDLE_FILENAME;
ps_handle.filename = persistent_script->full_path->val;
ps_handle.opened_path = persistent_script->full_path->val;
ps_handle.opened_path = persistent_script->full_path;
if (zend_get_file_handle_timestamp(&ps_handle, NULL) == persistent_script->timestamp) {
return SUCCESS;
@ -934,8 +937,8 @@ char *accel_make_persistent_key_ex(zend_file_handle *file_handle, int path_lengt
/* we don't handle this well for now. */
zend_accel_error(ACCEL_LOG_INFO, "getcwd() failed for '%s' (%d), please try to set opcache.use_cwd to 0 in ini file", file_handle->filename, errno);
if (file_handle->opened_path) {
cwd = file_handle->opened_path;
cwd_len = strlen(cwd);
cwd = file_handle->opened_path->val;
cwd_len = file_handle->opened_path->len;
} else {
ZCG(key_len) = 0;
return NULL;
@ -1047,7 +1050,7 @@ static inline char *accel_make_persistent_key(zend_file_handle *file_handle, int
int zend_accel_invalidate(const char *filename, int filename_len, zend_bool force)
{
char *realpath;
zend_string *realpath;
zend_persistent_script *persistent_script;
if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
@ -1060,12 +1063,12 @@ int zend_accel_invalidate(const char *filename, int filename_len, zend_bool forc
return FAILURE;
}
persistent_script = zend_accel_hash_find(&ZCSG(hash), realpath, strlen(realpath));
persistent_script = zend_accel_hash_find(&ZCSG(hash), realpath->val, realpath->len);
if (persistent_script && !persistent_script->corrupted) {
zend_file_handle file_handle;
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = realpath;
file_handle.filename = realpath->val;
file_handle.opened_path = realpath;
if (force ||
@ -1317,7 +1320,7 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
}
/* check blacklist right after ensuring that file was opened */
if (file_handle->opened_path && zend_accel_blacklist_is_blacklisted(&accel_blacklist, file_handle->opened_path)) {
if (file_handle->opened_path && zend_accel_blacklist_is_blacklisted(&accel_blacklist, file_handle->opened_path->val)) {
ZCSG(blacklist_misses)++;
*op_array_p = accelerator_orig_compile_file(file_handle, type);
return NULL;
@ -1439,7 +1442,7 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
}
if (file_handle->opened_path) {
new_persistent_script->full_path = zend_string_init(file_handle->opened_path, strlen(file_handle->opened_path), 0);
new_persistent_script->full_path = zend_string_copy(file_handle->opened_path);
} else {
new_persistent_script->full_path = zend_string_init(file_handle->filename, strlen(file_handle->filename), 0);
}
@ -1521,7 +1524,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
}
if (file_handle->opened_path &&
(bucket = zend_accel_hash_find_entry(&ZCSG(hash), file_handle->opened_path, strlen(file_handle->opened_path))) != NULL) {
(bucket = zend_accel_hash_find_entry(&ZCSG(hash), file_handle->opened_path->val, file_handle->opened_path->len)) != NULL) {
persistent_script = (zend_persistent_script *)bucket->data;
if (!ZCG(accel_directives).revalidate_path &&
@ -1702,7 +1705,7 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
(EG(current_execute_data) &&
(ZCG(cache_opline) == EG(current_execute_data)->opline))) {
persistent_script = ZCG(cache_persistent_script);
handle->opened_path = estrndup(persistent_script->full_path->val, persistent_script->full_path->len);
handle->opened_path = zend_string_copy(persistent_script->full_path);
handle->type = ZEND_HANDLE_FILENAME;
return SUCCESS;
#if 0
@ -1733,7 +1736,7 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
}
/* zend_resolve_path() replacement for PHP 5.3 and above */
static char* persistent_zend_resolve_path(const char *filename, int filename_len)
static zend_string* persistent_zend_resolve_path(const char *filename, int filename_len)
{
if (ZCG(enabled) && accel_startup_ok &&
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
@ -1752,7 +1755,7 @@ static char* persistent_zend_resolve_path(const char *filename, int filename_len
zend_file_handle handle;
char *key = NULL;
int key_length;
char *resolved_path;
zend_string *resolved_path;
zend_accel_hash_entry *bucket;
zend_persistent_script *persistent_script;
@ -1766,7 +1769,7 @@ static char* persistent_zend_resolve_path(const char *filename, int filename_len
ZCG(key_len) = persistent_script->full_path->len;
ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL;
ZCG(cache_persistent_script) = persistent_script;
return estrndup(persistent_script->full_path->val, persistent_script->full_path->len);
return zend_string_copy(persistent_script->full_path);
}
}
@ -1783,7 +1786,7 @@ static char* persistent_zend_resolve_path(const char *filename, int filename_len
/* we have persistent script */
ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL;
ZCG(cache_persistent_script) = persistent_script;
return estrndup(persistent_script->full_path->val, persistent_script->full_path->len);
return zend_string_copy(persistent_script->full_path);
}
/* find the full real path */
@ -1791,7 +1794,7 @@ static char* persistent_zend_resolve_path(const char *filename, int filename_len
/* Check if requested file already cached (by real path) */
if (resolved_path &&
(bucket = zend_accel_hash_find_entry(&ZCSG(hash), resolved_path, strlen(resolved_path))) != NULL) {
(bucket = zend_accel_hash_find_entry(&ZCSG(hash), resolved_path->val, resolved_path->len)) != NULL) {
persistent_script = (zend_persistent_script *)bucket->data;
if (persistent_script && !persistent_script->corrupted) {

19
ext/opcache/zend_accelerator_module.c

@ -278,25 +278,25 @@ ZEND_INI_BEGIN()
#endif
ZEND_INI_END()
static int filename_is_in_cache(char *filename, int filename_len)
static int filename_is_in_cache(zend_string *filename)
{
char *key;
int key_length;
zend_file_handle handle = {{0}, NULL, NULL, 0, 0};
zend_persistent_script *persistent_script;
handle.filename = filename;
handle.filename = filename->val;
handle.type = ZEND_HANDLE_FILENAME;
if (IS_ABSOLUTE_PATH(filename, filename_len)) {
persistent_script = zend_accel_hash_find(&ZCSG(hash), filename, filename_len);
if (IS_ABSOLUTE_PATH(filename->val, filename->len)) {
persistent_script = zend_accel_hash_find(&ZCSG(hash), filename->val, filename->len);
if (persistent_script) {
return !persistent_script->corrupted &&
validate_timestamp_and_record(persistent_script, &handle) == SUCCESS;
}
}
if ((key = accel_make_persistent_key_ex(&handle, filename_len, &key_length)) != NULL) {
if ((key = accel_make_persistent_key_ex(&handle, filename->len, &key_length)) != NULL) {
persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length);
return persistent_script && !persistent_script->corrupted &&
validate_timestamp_and_record(persistent_script, &handle) == SUCCESS;
@ -315,7 +315,7 @@ static int accel_file_in_cache(INTERNAL_FUNCTION_PARAMETERS)
Z_STRLEN(zfilename) == 0) {
return 0;
}
return filename_is_in_cache(Z_STRVAL(zfilename), Z_STRLEN(zfilename));
return filename_is_in_cache(Z_STR(zfilename));
}
static void accel_file_exists(INTERNAL_FUNCTION_PARAMETERS)
@ -734,8 +734,7 @@ static ZEND_FUNCTION(opcache_compile_file)
Return true if the script is cached in OPCache, false if it is not cached or if OPCache is not running. */
static ZEND_FUNCTION(opcache_is_script_cached)
{
char *script_name;
size_t script_name_len;
zend_string *script_name;
if (!validate_api_restriction()) {
RETURN_FALSE;
@ -745,9 +744,9 @@ static ZEND_FUNCTION(opcache_is_script_cached)
RETURN_FALSE;
}
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &script_name, &script_name_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &script_name) == FAILURE) {
return;
}
RETURN_BOOL(filename_is_in_cache(script_name, script_name_len));
RETURN_BOOL(filename_is_in_cache(script_name));
}

2
ext/phar/dirstream.c

@ -300,7 +300,7 @@ PHAR_ADD_ENTRY:
/**
* Open a directory handle within a phar archive
*/
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
{
php_url *resource = NULL;
php_stream *ret;

2
ext/phar/dirstream.h

@ -33,7 +33,7 @@ static int phar_dir_close(php_stream *stream, int close_handle);
static int phar_dir_flush(php_stream *stream);
static int phar_dir_seek( php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset);
#else
php_stream* phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
php_stream* phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
#endif
END_EXTERN_C()

33
ext/phar/func_interceptors.c

@ -118,6 +118,7 @@ PHAR_FUNC(phar_file_get_contents) /* {{{ */
if (use_include_path || (!IS_ABSOLUTE_PATH(filename, filename_len) && !strstr(filename, "://"))) {
char *arch, *entry, *fname;
zend_string *entry_str = NULL;
int arch_len, entry_len, fname_len;
php_stream_context *context = NULL;
@ -148,8 +149,8 @@ PHAR_FUNC(phar_file_get_contents) /* {{{ */
goto skip_phar;
}
if (use_include_path) {
if ((entry = phar_find_in_include_path(entry, entry_len, NULL))) {
name = entry;
if ((entry_str = phar_find_in_include_path(entry, entry_len, NULL))) {
name = entry_str->val;
goto phar_it;
} else {
/* this file is not in the phar, use the original path */
@ -188,7 +189,11 @@ phar_it:
context = php_stream_context_from_zval(zcontext, 0);
}
stream = php_stream_open_wrapper_ex(name, "rb", 0 | REPORT_ERRORS, NULL, context);
efree(name);
if (entry_str) {
zend_string_release(entry_str);
} else {
efree(name);
}
if (!stream) {
RETURN_FALSE;
@ -243,6 +248,7 @@ PHAR_FUNC(phar_readfile) /* {{{ */
}
if (use_include_path || (!IS_ABSOLUTE_PATH(filename, filename_len) && !strstr(filename, "://"))) {
char *arch, *entry, *fname;
zend_string *entry_str = NULL;
int arch_len, entry_len, fname_len;
php_stream_context *context = NULL;
char *name;
@ -267,12 +273,12 @@ PHAR_FUNC(phar_readfile) /* {{{ */
goto skip_phar;
}
if (use_include_path) {
if (!(entry = phar_find_in_include_path(entry, entry_len, NULL))) {
if (!(entry_str = phar_find_in_include_path(entry, entry_len, NULL))) {
/* this file is not in the phar, use the original path */
efree(arch);
goto skip_phar;
} else {
name = entry;
name = entry_str->val;
}
} else {
entry = phar_fix_filepath(estrndup(entry, entry_len), &entry_len, 1);
@ -301,7 +307,11 @@ notfound:
efree(arch);
context = php_stream_context_from_zval(zcontext, 0);
stream = php_stream_open_wrapper_ex(name, "rb", 0 | REPORT_ERRORS, NULL, context);
efree(name);
if (entry_str) {
zend_string_release(entry_str);
} else {
efree(name);
}
if (stream == NULL) {
RETURN_FALSE;
}
@ -339,6 +349,7 @@ PHAR_FUNC(phar_fopen) /* {{{ */
}
if (use_include_path || (!IS_ABSOLUTE_PATH(filename, filename_len) && !strstr(filename, "://"))) {
char *arch, *entry, *fname;
zend_string *entry_str = NULL;
int arch_len, entry_len, fname_len;
php_stream_context *context = NULL;
char *name;
@ -363,12 +374,12 @@ PHAR_FUNC(phar_fopen) /* {{{ */
goto skip_phar;
}
if (use_include_path) {
if (!(entry = phar_find_in_include_path(entry, entry_len, NULL))) {
if (!(entry_str = phar_find_in_include_path(entry, entry_len, NULL))) {
/* this file is not in the phar, use the original path */
efree(arch);
goto skip_phar;
} else {
name = entry;
name = entry_str->val;
}
} else {
entry = phar_fix_filepath(estrndup(entry, entry_len), &entry_len, 1);
@ -398,7 +409,11 @@ notfound:
efree(arch);
context = php_stream_context_from_zval(zcontext, 0);
stream = php_stream_open_wrapper_ex(name, mode, 0 | REPORT_ERRORS, NULL, context);
efree(name);
if (entry_str) {
zend_string_release(entry_str);
} else {
efree(name);
}
if (stream == NULL) {
RETURN_FALSE;
}

37
ext/phar/phar.c

@ -27,7 +27,7 @@
static void destroy_phar_data(zval *zv);
ZEND_DECLARE_MODULE_GLOBALS(phar)
char *(*phar_save_resolve_path)(const char *filename, int filename_len);
zend_string *(*phar_save_resolve_path)(const char *filename, int filename_len);
/**
* set's phar->is_writeable based on the current INI value
@ -1322,7 +1322,8 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a
{
phar_archive_data *mydata;
php_stream *fp;
char *actual = NULL, *p;
zend_string *actual = NULL;
char *p;
if (!pphar) {
pphar = &mydata;
@ -1340,8 +1341,8 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a
fp = php_stream_open_wrapper(fname, "rb", IGNORE_URL|STREAM_MUST_SEEK|0, &actual);
if (actual) {
fname = actual;
fname_len = strlen(actual);
fname = actual->val;
fname_len = actual->len;
}
if (fp) {
@ -1350,20 +1351,20 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a
(*pphar)->is_writeable = 1;
}
if (actual) {
efree(actual);
zend_string_release(actual);
}
return SUCCESS;
} else {
/* file exists, but is either corrupt or not a phar archive */
if (actual) {
efree(actual);
zend_string_release(actual);
}
return FAILURE;
}
}
if (actual) {
efree(actual);
zend_string_release(actual);
}
if (PHAR_G(readonly) && !is_data) {
@ -1475,7 +1476,7 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a
int phar_open_from_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error) /* {{{ */
{
php_stream *fp;
char *actual;
zend_string *actual;
int ret, is_data = 0;
if (error) {
@ -1509,20 +1510,20 @@ int phar_open_from_filename(char *fname, int fname_len, char *alias, int alias_l
}
}
if (actual) {
efree(actual);
zend_string_release(actual);
}
return FAILURE;
}
if (actual) {
fname = actual;
fname_len = strlen(actual);
fname = actual->val;
fname_len = actual->len;
}
ret = phar_open_from_fp(fp, fname, fname_len, alias, alias_len, options, pphar, is_data, error);
if (actual) {
efree(actual);
zend_string_release(actual);
}
return ret;
@ -2252,7 +2253,7 @@ int phar_open_executed_filename(char *alias, int alias_len, char **error) /* {{{
char *fname;
php_stream *fp;
int fname_len;
char *actual = NULL;
zend_string *actual = NULL;
int ret;
if (error) {
@ -2298,20 +2299,20 @@ int phar_open_executed_filename(char *alias, int alias_len, char **error) /* {{{
spprintf(error, 0, "unable to open phar for reading \"%s\"", fname);
}
if (actual) {
efree(actual);
zend_string_release(actual);
}
return FAILURE;
}
if (actual) {
fname = actual;
fname_len = strlen(actual);
fname = actual->val;
fname_len = actual->len;
}
ret = phar_open_from_fp(fp, fname, fname_len, alias, alias_len, REPORT_ERRORS, NULL, 0, error);
if (actual) {
efree(actual);
zend_string_release(actual);
}
return ret;
@ -3254,7 +3255,7 @@ static size_t phar_zend_stream_fsizer(void *handle) /* {{{ */
zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type);
#define phar_orig_zend_open zend_stream_open_function
static char *phar_resolve_path(const char *filename, int filename_len)
static zend_string *phar_resolve_path(const char *filename, int filename_len)
{
return phar_find_in_include_path((char *) filename, filename_len, NULL);
}

4
ext/phar/phar_internal.h

@ -495,7 +495,7 @@ union _phar_entry_object {
#endif
#ifndef PHAR_MAIN
extern char *(*phar_save_resolve_path)(const char *filename, int filename_len);
extern zend_string *(*phar_save_resolve_path)(const char *filename, int filename_len);
#endif
BEGIN_EXTERN_C()
@ -562,7 +562,7 @@ char *phar_compress_filter(phar_entry_info * entry, int return_unknown);
void phar_remove_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len);
char *phar_find_in_include_path(char *file, int file_len, phar_archive_data **pphar);
zend_string *phar_find_in_include_path(char *file, int file_len, phar_archive_data **pphar);
char *phar_fix_filepath(char *path, int *new_len, int use_cwd);
phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error);
int phar_parse_metadata(char **buffer, zval *metadata, int zip_metadata_len);

19
ext/phar/phar_object.c

@ -1399,11 +1399,11 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
phar_entry_data *data;
php_stream *fp;
size_t contents_len;
char *fname, *error = NULL, *base = p_obj->b, *opened, *save = NULL, *temp = NULL;
char *fname, *error = NULL, *base = p_obj->b, *save = NULL, *temp = NULL;
zend_string *opened;
char *str_key;
zend_class_entry *ce = p_obj->c;
phar_archive_object *phar_obj = p_obj->p;
char *str = "[stream]";
value = iter->funcs->get_current_data(iter);
@ -1453,7 +1453,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
}
close_fp = 0;
opened = (char *) estrndup(str, sizeof("[stream]") - 1);
opened = zend_string_init("[stream]", sizeof("[stream]") - 1, 0);
goto after_open_fp;
case IS_OBJECT:
if (instanceof_function(Z_OBJCE_P(value), spl_ce_SplFileInfo)) {
@ -1638,7 +1638,7 @@ after_open_fp:
}
if (opened) {
efree(opened);
zend_string_release(opened);
}
if (close_fp) {
@ -1657,7 +1657,7 @@ after_open_fp:
}
if (opened) {
efree(opened);
zend_string_release(opened);
}
if (temp) {
@ -1692,9 +1692,7 @@ after_open_fp:
php_stream_close(fp);
}
// TODO: avoid reallocation ???
add_assoc_string(p_obj->ret, str_key, opened);
efree(opened);
add_assoc_str(p_obj->ret, str_key, opened);
if (save) {
efree(save);
@ -4202,7 +4200,7 @@ PHP_METHOD(Phar, extractTo)
php_stream *fp;
php_stream_statbuf ssb;
phar_entry_info *entry;
char *pathto, *filename, *actual;
char *pathto, *filename;
size_t pathto_len, filename_len;
int ret, i;
int nelems;
@ -4215,7 +4213,7 @@ PHP_METHOD(Phar, extractTo)
return;
}
fp = php_stream_open_wrapper(phar_obj->archive->fname, "rb", IGNORE_URL|STREAM_MUST_SEEK, &actual);
fp = php_stream_open_wrapper(phar_obj->archive->fname, "rb", IGNORE_URL|STREAM_MUST_SEEK, NULL);
if (!fp) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
@ -4223,7 +4221,6 @@ PHP_METHOD(Phar, extractTo)
return;
}
efree(actual);
php_stream_close(fp);
if (pathto_len < 1) {

10
ext/phar/stream.c

@ -155,7 +155,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const
/**
* used for fopen('phar://...') and company
*/
static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
{
phar_archive_data *phar;
phar_entry_data *idata;
@ -231,7 +231,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
}
}
if (opened_path) {
spprintf(opened_path, MAXPATHLEN, "phar://%s/%s", idata->phar->fname, idata->internal_file->filename);
*opened_path = zend_strpprintf(MAXPATHLEN, "phar://%s/%s", idata->phar->fname, idata->internal_file->filename);
}
return fpf;
} else {
@ -249,7 +249,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
}
efree(internal_file);
if (opened_path) {
spprintf(opened_path, MAXPATHLEN, "%s", phar->fname);
*opened_path = zend_strpprintf(MAXPATHLEN, "%s", phar->fname);
}
php_url_free(resource);
goto phar_stub;
@ -275,7 +275,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
++(entry->fp_refcount);
php_url_free(resource);
if (opened_path) {
spprintf(opened_path, MAXPATHLEN, "%s", phar->fname);
*opened_path = zend_strpprintf(MAXPATHLEN, "%s", phar->fname);
}
efree(internal_file);
goto phar_stub;
@ -332,7 +332,7 @@ idata_error:
}
}
if (opened_path) {
spprintf(opened_path, MAXPATHLEN, "phar://%s/%s", idata->phar->fname, idata->internal_file->filename);
*opened_path = zend_strpprintf(MAXPATHLEN, "phar://%s/%s", idata->phar->fname, idata->internal_file->filename);
}
efree(internal_file);
phar_stub:

2
ext/phar/stream.h

@ -24,7 +24,7 @@ BEGIN_EXTERN_C()
php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options);
void phar_entry_remove(phar_entry_data *idata, char **error);
static php_stream* phar_wrapper_open_url(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
static php_stream* phar_wrapper_open_url(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context);
static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context);
static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context);

17
ext/phar/util.c

@ -250,10 +250,11 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
}
/* }}} */
char *phar_find_in_include_path(char *filename, int filename_len, phar_archive_data **pphar) /* {{{ */
zend_string *phar_find_in_include_path(char *filename, int filename_len, phar_archive_data **pphar) /* {{{ */
{
char *path, *fname, *arch, *entry, *ret, *test;
int arch_len, entry_len, fname_len, ret_len;
zend_string *ret;
char *path, *fname, *arch, *entry, *test;
int arch_len, entry_len, fname_len;
phar_archive_data *phar;
if (pphar) {
@ -299,14 +300,14 @@ splitted:
if (*test == '/') {
if (zend_hash_str_exists(&(phar->manifest), test + 1, try_len - 1)) {
spprintf(&ret, 0, "phar://%s%s", arch, test);
ret = zend_strpprintf(0, "phar://%s%s", arch, test);
efree(arch);
efree(test);
return ret;
}
} else {
if (zend_hash_str_exists(&(phar->manifest), test, try_len)) {
spprintf(&ret, 0, "phar://%s/%s", arch, test);
ret = zend_strpprintf(0, "phar://%s/%s", arch, test);
efree(arch);
efree(test);
return ret;
@ -320,11 +321,9 @@ splitted:
ret = php_resolve_path(filename, filename_len, path);
efree(path);
if (ret && strlen(ret) > 8 && !strncmp(ret, "phar://", 7)) {
ret_len = strlen(ret);
if (ret && ret->len > 8 && !strncmp(ret->val, "phar://", 7)) {
/* found phar:// */
if (SUCCESS != phar_split_fname(ret, ret_len, &arch, &arch_len, &entry, &entry_len, 1, 0)) {
if (SUCCESS != phar_split_fname(ret->val, ret->len, &arch, &arch_len, &entry, &entry_len, 1, 0)) {
return ret;
}

4
ext/spl/php_spl.c

@ -273,9 +273,9 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha
if (ret == SUCCESS) {
zend_string *opened_path;
if (!file_handle.opened_path) {
file_handle.opened_path = estrndup(class_file, class_file_len);
file_handle.opened_path = zend_string_init(class_file, class_file_len, 0);
}
opened_path = zend_string_init(file_handle.opened_path, strlen(file_handle.opened_path), 0);
opened_path = zend_string_copy(file_handle.opened_path);
ZVAL_NULL(&dummy);
if (zend_hash_add(&EG(included_files), opened_path, &dummy)) {
new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE);

6
ext/standard/file.c

@ -802,7 +802,7 @@ PHP_FUNCTION(tempnam)
{
char *dir, *prefix;
size_t dir_len, prefix_len;
char *opened_path;
zend_string *opened_path;
int fd;
zend_string *p;
@ -823,9 +823,7 @@ PHP_FUNCTION(tempnam)
if ((fd = php_open_temporary_fd_ex(dir, p->val, &opened_path, 1)) >= 0) {
close(fd);
// TODO: avoid reallocation ???
RETVAL_STRING(opened_path);
efree(opened_path);
RETVAL_STR(opened_path);
}
zend_string_release(p);
}

6
ext/standard/ftp_fopen_wrapper.c

@ -131,7 +131,7 @@ static int php_stream_ftp_stream_close(php_stream_wrapper *wrapper, php_stream *
/* {{{ php_ftp_fopen_connect
*/
static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char *path, const char *mode, int options,
char **opened_path, php_stream_context *context, php_stream **preuseid,
zend_string **opened_path, php_stream_context *context, php_stream **preuseid,
php_url **presource, int *puse_ssl, int *puse_ssl_on_data)
{
php_stream *stream = NULL, *reuseid = NULL;
@ -412,7 +412,7 @@ static unsigned short php_fopen_do_pasv(php_stream *stream, char *ip, size_t ip_
/* {{{ php_fopen_url_wrap_ftp
*/
php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *path, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC)
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
php_stream *stream = NULL, *datastream = NULL;
php_url *resource = NULL;
@ -684,7 +684,7 @@ static php_stream_ops php_ftp_dirstream_ops = {
/* {{{ php_stream_ftp_opendir
*/
php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options,
char **opened_path, php_stream_context *context STREAMS_DC)
zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
php_stream *stream, *reuseid, *datastream = NULL;
php_ftp_dirstream_data *dirsdata;

4
ext/standard/http_fopen_wrapper.c

@ -110,7 +110,7 @@ static inline void strip_header(char *header_bag, char *lc_header_bag,
}
php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
const char *path, const char *mode, int options, char **opened_path,
const char *path, const char *mode, int options, zend_string **opened_path,
php_stream_context *context, int redirect_max, int flags STREAMS_DC) /* {{{ */
{
php_stream *stream = NULL;
@ -933,7 +933,7 @@ out:
}
/* }}} */
php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
{
return php_stream_url_wrap_http_ex(wrapper, path, mode, options, opened_path, context, PHP_URL_REDIRECT_MAX, HTTP_WRAPPER_HEADER_INIT STREAMS_CC);
}

3
ext/standard/php_fopen_wrapper.c

@ -172,7 +172,7 @@ static void php_stream_apply_filter_list(php_stream *stream, char *filterlist, i
/* }}} */
php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *path, const char *mode, int options,
char **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
zend_string **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
{
int fd = -1;
int mode_rw = 0;
@ -345,6 +345,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa
efree(pathdup);
return NULL;
}
if (!(stream = php_stream_open_wrapper(p + 10, mode, options, opened_path))) {
efree(pathdup);
return NULL;

4
ext/standard/php_fopen_wrappers.h

@ -23,8 +23,8 @@
#ifndef PHP_FOPEN_WRAPPERS_H
#define PHP_FOPEN_WRAPPERS_H
php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
php_stream *php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
php_stream *php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
extern PHPAPI php_stream_wrapper php_stream_http_wrapper;
extern PHPAPI php_stream_wrapper php_stream_ftp_wrapper;
extern PHPAPI php_stream_wrapper php_stream_php_wrapper;

8
ext/standard/streamsfuncs.c

@ -1489,8 +1489,9 @@ PHP_FUNCTION(stream_socket_enable_crypto)
Determine what file will be opened by calls to fopen() with a relative path */
PHP_FUNCTION(stream_resolve_include_path)
{
char *filename, *resolved_path;
char *filename;
size_t filename_len;
zend_string *resolved_path;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) {
return;
@ -1499,10 +1500,7 @@ PHP_FUNCTION(stream_resolve_include_path)
resolved_path = zend_resolve_path(filename, (int)filename_len);
if (resolved_path) {
// TODO: avoid reallocation ???
RETVAL_STRING(resolved_path);
efree(resolved_path);
return;
RETURN_STR(resolved_path);
}
RETURN_FALSE;
}

2
ext/zip/php_zip.h

@ -90,7 +90,7 @@ static inline ze_zip_object *php_zip_fetch_object(zend_object *obj) {
#define Z_ZIP_P(zv) php_zip_fetch_object(Z_OBJ_P((zv)))
php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
php_stream *php_stream_zip_open(const char *filename, const char *path, const char *mode STREAMS_DC);
extern php_stream_wrapper php_stream_zip_wrapper;

4
ext/zip/zip_stream.c

@ -254,7 +254,7 @@ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper,
const char *path,
const char *mode,
int options,
char **opened_path,
zend_string **opened_path,
php_stream_context *context STREAMS_DC)
{
int path_len;
@ -314,7 +314,7 @@ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper,
stream = php_stream_alloc(&php_stream_zipio_ops, self, NULL, mode);
if (opened_path) {
*opened_path = estrdup(path);
*opened_path = zend_string_init(path, strlen(path), 0);
}
} else {
zip_close(za);

2
ext/zlib/php_zlib.h

@ -58,7 +58,7 @@ ZEND_BEGIN_MODULE_GLOBALS(zlib)
int compression_coding;
ZEND_END_MODULE_GLOBALS(zlib);
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
extern php_stream_ops php_stream_gzio_ops;
extern php_stream_wrapper php_stream_gzip_wrapper;
extern php_stream_filter_factory php_zlib_filter_factory;

2
ext/zlib/zlib_fopen_wrapper.c

@ -111,7 +111,7 @@ php_stream_ops php_stream_gzio_ops = {
};
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options,
char **opened_path, php_stream_context *context STREAMS_DC)
zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
struct php_gz_stream_data_t *self;
php_stream *stream = NULL, *innerstream = NULL;

29
main/fopen_wrappers.c

@ -340,7 +340,7 @@ PHPAPI int php_check_open_basedir_ex(const char *path, int warn)
/* {{{ php_fopen_and_set_opened_path
*/
static FILE *php_fopen_and_set_opened_path(const char *path, const char *mode, char **opened_path)
static FILE *php_fopen_and_set_opened_path(const char *path, const char *mode, zend_string **opened_path)
{
FILE *fp;
@ -349,7 +349,12 @@ static FILE *php_fopen_and_set_opened_path(const char *path, const char *mode, c
}
fp = VCWD_FOPEN(path, mode);
if (fp && opened_path) {
*opened_path = expand_filepath_with_mode(path, NULL, NULL, 0, CWD_EXPAND);
//TODO :avoid reallocation
char *tmp = expand_filepath_with_mode(path, NULL, NULL, 0, CWD_EXPAND);
if (tmp) {
*opened_path = zend_string_init(tmp, strlen(tmp), 0);
efree(tmp);
}
}
return fp;
}
@ -361,7 +366,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
{
char *path_info;
char *filename = NULL;
char *resolved_path = NULL;
zend_string *resolved_path = NULL;
int length;
zend_bool orig_display_errors;
@ -448,7 +453,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
}
return FAILURE;
}
efree(resolved_path);
zend_string_release(resolved_path);
orig_display_errors = PG(display_errors);
PG(display_errors) = 0;
@ -481,7 +486,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
/* {{{ php_resolve_path
* Returns the realpath for given filename according to include path
*/
PHPAPI char *php_resolve_path(const char *filename, int filename_length, const char *path)
PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length, const char *path)
{
char resolved_path[MAXPATHLEN];
char trypath[MAXPATHLEN];
@ -499,7 +504,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
wrapper = php_stream_locate_url_wrapper(filename, &actual_path, STREAM_OPEN_FOR_INCLUDE);
if (wrapper == &php_plain_files_wrapper) {
if (tsrm_realpath(actual_path, resolved_path)) {
return estrdup(resolved_path);
return zend_string_init(resolved_path, strlen(resolved_path), 0);
}
}
return NULL;
@ -512,7 +517,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
!path ||
!*path) {
if (tsrm_realpath(filename, resolved_path)) {
return estrdup(resolved_path);
return zend_string_init(resolved_path, strlen(resolved_path), 0);
} else {
return NULL;
}
@ -562,14 +567,14 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
php_stream_statbuf ssb;
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
return estrdup(trypath);
return zend_string_init(trypath, strlen(trypath), 0);
}
}
continue;
}
}
if (tsrm_realpath(actual_path, resolved_path)) {
return estrdup(resolved_path);
return zend_string_init(resolved_path, strlen(resolved_path), 0);
}
} /* end provided path */
@ -598,7 +603,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
php_stream_statbuf ssb;
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
return estrdup(trypath);
return zend_string_init(trypath, strlen(trypath), 0);
}
}
return NULL;
@ -606,7 +611,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
}
if (tsrm_realpath(actual_path, resolved_path)) {
return estrdup(resolved_path);
return zend_string_init(resolved_path, strlen(resolved_path), 0);
}
}
}
@ -619,7 +624,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
* Tries to open a file with a PATH-style list of directories.
* If the filename starts with "." or "/", the path is ignored.
*/
PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path)
PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path)
{
char *pathbuf, *ptr, *end;
const char *exec_fname;

4
main/fopen_wrappers.h

@ -46,9 +46,9 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path
PHPAPI int php_check_safe_mode_include_dir(const char *path);
PHPAPI char *php_resolve_path(const char *filename, int filename_len, const char *path);
PHPAPI zend_string *php_resolve_path(const char *filename, int filename_len, const char *path);
PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path);
PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path);
PHPAPI char *php_strip_url_passwd(char *path);

11
main/main.c

@ -1350,7 +1350,7 @@ PHP_FUNCTION(set_time_limit)
/* {{{ php_fopen_wrapper_for_zend
*/
static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path)
static FILE *php_fopen_wrapper_for_zend(const char *filename, zend_string **opened_path)
{
return php_stream_open_wrapper_as_file((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
}
@ -1428,7 +1428,7 @@ PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *h
}
/* }}} */
static char *php_resolve_path_for_zend(const char *filename, int filename_len) /* {{{ */
static zend_string *php_resolve_path_for_zend(const char *filename, int filename_len) /* {{{ */
{
return php_resolve_path(filename, filename_len, PG(include_path));
}
@ -2490,12 +2490,9 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file)
primary_file->opened_path == NULL &&
primary_file->type != ZEND_HANDLE_FILENAME
) {
int realfile_len;
if (expand_filepath(primary_file->filename, realfile)) {
realfile_len = (int)strlen(realfile);
zend_hash_str_add_empty_element(&EG(included_files), realfile, realfile_len);
primary_file->opened_path = estrndup(realfile, realfile_len);
primary_file->opened_path = zend_string_init(realfile, strlen(realfile), 0);
zend_hash_add_empty_element(&EG(included_files), primary_file->opened_path);
}
}

16
main/php_ini.c

@ -389,6 +389,7 @@ int php_init_config(void)
char *open_basedir;
int free_ini_search_path = 0;
zend_file_handle fh;
zend_string *opened_path = NULL;
zend_hash_init(&configuration_hash, 8, NULL, config_zval_dtor, 1);
@ -555,7 +556,8 @@ int php_init_config(void)
if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
fh.handle.fp = VCWD_FOPEN(php_ini_file_name, "r");
if (fh.handle.fp) {
fh.filename = php_ini_opened_path = expand_filepath(php_ini_file_name, NULL);
fh.filename = expand_filepath(php_ini_file_name, NULL);
opened_path = zend_string_init(fh.filename, strlen(fh.filename), 0);
}
}
}
@ -566,18 +568,18 @@ int php_init_config(void)
const char *fmt = "php-%s.ini";
char *ini_fname;
spprintf(&ini_fname, 0, fmt, sapi_module.name);
fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path);
fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &opened_path);
efree(ini_fname);
if (fh.handle.fp) {
fh.filename = php_ini_opened_path;
fh.filename = opened_path->val;
}
}
/* If still no ini file found, search for php.ini file in search path */
if (!fh.handle.fp) {
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path);
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
if (fh.handle.fp) {
fh.filename = php_ini_opened_path;
fh.filename = opened_path->val;
}
}
}
@ -599,8 +601,8 @@ int php_init_config(void)
ZVAL_NEW_STR(&tmp, zend_string_init(fh.filename, strlen(fh.filename), 1));
zend_hash_str_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path")-1, &tmp);
if (php_ini_opened_path) {
efree(php_ini_opened_path);
if (opened_path) {
zend_string_release(opened_path);
}
php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
}

20
main/php_open_temporary_file.c

@ -94,10 +94,10 @@
* SUCH DAMAGE.
*/
static int php_do_open_temporary_file(const char *path, const char *pfx, char **opened_path_p)
static int php_do_open_temporary_file(const char *path, const char *pfx, zend_string **opened_path_p)
{
char *trailing_slash;
char *opened_path;
char opened_path[MAXPATHLEN];
char cwd[MAXPATHLEN];
cwd_state new_state;
int fd = -1;
@ -138,8 +138,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
trailing_slash = "/";
}
if (spprintf(&opened_path, 0, "%s%s%sXXXXXX", new_state.cwd, trailing_slash, pfx) >= MAXPATHLEN) {
efree(opened_path);
if (snprintf(opened_path, MAXPATHLEN, "%s%s%sXXXXXX", new_state.cwd, trailing_slash, pfx) >= MAXPATHLEN) {
efree(new_state.cwd);
return -1;
}
@ -150,7 +149,6 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
/* Some versions of windows set the temp file to be read-only,
* which means that opening it will fail... */
if (VCWD_CHMOD(opened_path, 0600)) {
efree(opened_path);
efree(new_state.cwd);
return -1;
}
@ -165,10 +163,8 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
}
#endif
if (fd == -1 || !opened_path_p) {
efree(opened_path);
} else {
*opened_path_p = opened_path;
if (fd != -1 && opened_path_p) {
*opened_path_p = zend_string_init(opened_path, strlen(opened_path), 0);
}
efree(new_state.cwd);
return fd;
@ -264,7 +260,7 @@ PHPAPI const char* php_get_temporary_directory(void)
* This function should do its best to return a file pointer to a newly created
* unique file, on every platform.
*/
PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, char **opened_path_p, zend_bool open_basedir_check)
PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, zend_bool open_basedir_check)
{
int fd;
const char *temp_dir;
@ -296,12 +292,12 @@ def_tmp:
return fd;
}
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p)
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, zend_string **opened_path_p)
{
return php_open_temporary_fd_ex(dir, pfx, opened_path_p, 0);
}
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, char **opened_path_p)
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, zend_string **opened_path_p)
{
FILE *fp;
int fd = php_open_temporary_fd(dir, pfx, opened_path_p);

6
main/php_open_temporary_file.h

@ -22,9 +22,9 @@
#define PHP_OPEN_TEMPORARY_FILE_H
BEGIN_EXTERN_C()
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, char **opened_path_p);
PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, char **opened_path_p, zend_bool open_basedir_check);
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p);
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, zend_string **opened_path_p);
PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, zend_bool open_basedir_check);
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, zend_string **opened_path_p);
PHPAPI const char *php_get_temporary_directory(void);
PHPAPI void php_shutdown_temporary_directory(void);
END_EXTERN_C()

6
main/php_streams.h

@ -134,7 +134,7 @@ typedef struct _php_stream_ops {
typedef struct _php_stream_wrapper_ops {
/* open/create a wrapped stream */
php_stream *(*stream_opener)(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC);
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
/* close/destroy a wrapped stream */
int (*stream_closer)(php_stream_wrapper *wrapper, php_stream *stream);
/* stat a wrapped stream */
@ -143,7 +143,7 @@ typedef struct _php_stream_wrapper_ops {
int (*url_stat)(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context);
/* open a "directory" stream */
php_stream *(*dir_opener)(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC);
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
const char *label;
@ -554,7 +554,7 @@ PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrap
PHPAPI int php_unregister_url_stream_wrapper(const char *protocol);
PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper);
PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol);
PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options);
PHPAPI const char *php_stream_locate_eol(php_stream *stream, zend_string *buf);

35
main/rfc1867.c

@ -191,16 +191,16 @@ static void register_http_post_files_variable_ex(char *var, zval *val, zval *htt
static int unlink_filename(zval *el) /* {{{ */
{
char *filename = (char*)Z_PTR_P(el);
VCWD_UNLINK(filename);
zend_string *filename = Z_STR_P(el);
VCWD_UNLINK(filename->val);
return 0;
}
/* }}} */
static void free_filename(zval *el) {
char *filename = (char*)Z_PTR_P(el);
efree(filename);
zend_string *filename = Z_STR_P(el);
zend_string_release(filename);
}
void destroy_uploaded_files_hash(void) /* {{{ */
@ -685,7 +685,8 @@ static char *multipart_buffer_read_body(multipart_buffer *self, size_t *len)
SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
{
char *boundary, *s = NULL, *boundary_end = NULL, *start_arr = NULL, *array_index = NULL;
char *temp_filename = NULL, *lbuf = NULL, *abuf = NULL;
char *lbuf = NULL, *abuf = NULL;
zend_string *temp_filename = NULL;
int boundary_len = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
int64_t total_bytes = 0, max_file_size = 0;
int skip_upload = 0, anonindex = 0, is_anonymous;
@ -980,7 +981,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
event_file_start.name = param;
event_file_start.filename = &filename;
if (php_rfc1867_callback(MULTIPART_EVENT_FILE_START, &event_file_start, &event_extra_data) == FAILURE) {
temp_filename = "";
temp_filename = NULL;
efree(param);
efree(filename);
continue;
@ -1095,7 +1096,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
multipart_event_file_end event_file_end;
event_file_end.post_bytes_processed = SG(read_post_bytes);
event_file_end.temp_filename = temp_filename;
event_file_end.temp_filename = temp_filename->val;
event_file_end.cancel_upload = cancel_upload;
if (php_rfc1867_callback(MULTIPART_EVENT_FILE_END, &event_file_end, &event_extra_data) == FAILURE) {
cancel_upload = UPLOAD_ERROR_X;
@ -1105,13 +1106,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
if (cancel_upload) {
if (temp_filename) {
if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */
unlink(temp_filename);
unlink(temp_filename->val);
}
efree(temp_filename);
zend_string_release(temp_filename);
}
temp_filename = "";
temp_filename = NULL;
} else {
zend_hash_str_add_ptr(SG(rfc1867_uploaded_files), temp_filename, strlen(temp_filename), temp_filename);
zend_hash_add_ptr(SG(rfc1867_uploaded_files), temp_filename, temp_filename);
}
/* is_arr_upload is true when name of file upload field
@ -1211,7 +1212,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
/* if param is of form xxx[.*] this will cut it to xxx */
if (!is_anonymous) {
ZVAL_STRING(&zfilename, temp_filename);
if (temp_filename) {
ZVAL_STR_COPY(&zfilename, temp_filename);
} else {
ZVAL_EMPTY_STRING(&zfilename);
}
safe_php_register_variable_ex(param, &zfilename, NULL, 1);
}
@ -1222,7 +1227,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
snprintf(lbuf, llen, "%s[tmp_name]", param);
}
add_protected_variable(lbuf);
ZVAL_STRING(&zfilename, temp_filename);
if (temp_filename) {
ZVAL_STR_COPY(&zfilename, temp_filename);
} else {
ZVAL_EMPTY_STRING(&zfilename);
}
register_http_post_files_variable_ex(lbuf, &zfilename, &PG(http_globals)[TRACK_VARS_FILES], 1);
}

4
main/streams/cast.c

@ -342,7 +342,7 @@ exit_success:
/* }}} */
/* {{{ php_stream_open_wrapper_as_file */
PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int options, char **opened_path STREAMS_DC)
PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int options, zend_string **opened_path STREAMS_DC)
{
FILE *fp = NULL;
php_stream *stream = NULL;
@ -356,7 +356,7 @@ PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int optio
if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, (void**)&fp, REPORT_ERRORS) == FAILURE) {
php_stream_close(stream);
if (opened_path && *opened_path) {
efree(*opened_path);
zend_string_release(*opened_path);
}
return NULL;
}

4
main/streams/glob_wrapper.c

@ -207,7 +207,7 @@ php_stream_ops php_glob_stream_ops = {
/* {{{ php_glob_stream_opener */
static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC)
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
glob_s_t *pglob;
int ret;
@ -220,7 +220,7 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha
if (!strncmp(path, "glob://", sizeof("glob://")-1)) {
path += sizeof("glob://")-1;
if (opened_path) {
*opened_path = estrdup(path);
*opened_path = zend_string_init(path, strlen(path), 0);
}
}

2
main/streams/memory.c

@ -619,7 +619,7 @@ PHPAPI php_stream_ops php_stream_rfc2397_ops = {
};
static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, const char *path,
const char *mode, int options, char **opened_path,
const char *mode, int options, zend_string **opened_path,
php_stream_context *context STREAMS_DC) /* {{{ */
{
php_stream *stream;

8
main/streams/php_stream_plain_wrapper.h

@ -27,10 +27,10 @@ PHPAPI extern php_stream_wrapper php_plain_files_wrapper;
BEGIN_EXTERN_C()
/* like fopen, but returns a stream */
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC);
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zend_string **opened_path, int options STREAMS_DC);
#define php_stream_fopen(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened), 0 STREAMS_CC)
PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC);
PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path, int options STREAMS_DC);
#define php_stream_fopen_with_path(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened), 0 STREAMS_CC)
PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC);
@ -45,13 +45,13 @@ PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STRE
PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC);
#define php_stream_fopen_tmpfile() _php_stream_fopen_tmpfile(0 STREAMS_CC)
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC);
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, zend_string **opened_path STREAMS_DC);
#define php_stream_fopen_temporary_file(dir, pfx, opened_path) _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_CC)
/* This is a utility API for extensions that are opening a stream, converting it
* to a FILE* and then closing it again. Be warned that fileno() on the result
* will most likely fail on systems with fopencookie. */
PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int options, char **opened_path STREAMS_DC);
PHPAPI FILE * _php_stream_open_wrapper_as_file(char * path, char * mode, int options, zend_string **opened_path STREAMS_DC);
#define php_stream_open_wrapper_as_file(path, mode, options, opened_path) _php_stream_open_wrapper_as_file((path), (mode), (options), (opened_path) STREAMS_CC)
END_EXTERN_C()

54
main/streams/plain_wrapper.c

@ -124,7 +124,7 @@ typedef struct {
unsigned _reserved:29;
int lock_flag; /* stores the lock state */
char *temp_file_name; /* if non-null, this is the path to a temporary file that
zend_string *temp_name; /* if non-null, this is the path to a temporary file that
* is to be deleted when the stream is closed */
#if HAVE_FLUSHIO
char last_op;
@ -168,7 +168,7 @@ static php_stream *_php_stream_fopen_from_fd_int(int fd, const char *mode, const
self->is_pipe = 0;
self->lock_flag = LOCK_UN;
self->is_process_pipe = 0;
self->temp_file_name = NULL;
self->temp_name = NULL;
self->fd = fd;
return php_stream_alloc_rel(&php_stream_stdio_ops, self, persistent_id, mode);
@ -184,15 +184,15 @@ static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char *mode
self->is_pipe = 0;
self->lock_flag = LOCK_UN;
self->is_process_pipe = 0;
self->temp_file_name = NULL;
self->temp_name = NULL;
self->fd = fileno(file);
return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
}
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path_ptr STREAMS_DC)
PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, zend_string **opened_path_ptr STREAMS_DC)
{
char *opened_path = NULL;
zend_string *opened_path = NULL;
int fd;
fd = php_open_temporary_fd(dir, pfx, &opened_path);
@ -207,9 +207,9 @@ PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char
if (stream) {
php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract;
stream->wrapper = &php_plain_files_wrapper;
stream->orig_path = estrdup(opened_path);
stream->orig_path = estrndup(opened_path->val, opened_path->len);
self->temp_file_name = opened_path;
self->temp_name = opened_path;
self->lock_flag = LOCK_UN;
return stream;
@ -311,7 +311,7 @@ PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STRE
self->lock_flag = LOCK_UN;
self->is_process_pipe = 1;
self->fd = fileno(file);
self->temp_file_name = NULL;
self->temp_name = NULL;
stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
@ -450,11 +450,11 @@ static int php_stdiop_close(php_stream *stream, int close_handle)
} else {
return 0; /* everything should be closed already -> success */
}
if (data->temp_file_name) {
unlink(data->temp_file_name);
if (data->temp_name) {
unlink(data->temp_name->val);
/* temporary streams are never persistent */
efree(data->temp_file_name);
data->temp_file_name = NULL;
zend_string_release(data->temp_name);
data->temp_name = NULL;
}
} else {
ret = 0;
@ -890,7 +890,7 @@ static php_stream_ops php_plain_files_dirstream_ops = {
};
static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC)
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
DIR *dir = NULL;
php_stream *stream = NULL;
@ -928,9 +928,9 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const
/* }}} */
/* {{{ php_stream_fopen */
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC)
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zend_string **opened_path, int options STREAMS_DC)
{
char *realpath = NULL;
char realpath[MAXPATHLEN];
int open_flags;
int fd;
php_stream *ret;
@ -945,9 +945,9 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
}
if (options & STREAM_ASSUME_REALPATH) {
realpath = estrdup(filename);
strlcpy(realpath, filename, sizeof(realpath));
} else {
if ((realpath = expand_filepath(filename, NULL)) == NULL) {
if (expand_filepath(filename, realpath) == NULL) {
return NULL;
}
}
@ -957,15 +957,12 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
switch (php_stream_from_persistent_id(persistent_id, &ret)) {
case PHP_STREAM_PERSISTENT_SUCCESS:
if (opened_path) {
*opened_path = realpath;
realpath = NULL;
//TODO: avoid reallocation???
*opened_path = zend_string_init(realpath, strlen(realpath), 0);
}
/* fall through */
case PHP_STREAM_PERSISTENT_FAILURE:
if (realpath) {
efree(realpath);
}
efree(persistent_id);;
return ret;
}
@ -983,11 +980,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
if (ret) {
if (opened_path) {
*opened_path = realpath;
realpath = NULL;
}
if (realpath) {
efree(realpath);
*opened_path = zend_string_init(realpath, strlen(realpath), 0);
}
if (persistent_id) {
efree(persistent_id);
@ -1005,7 +998,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
r = do_fstat(self, 0);
if ((r == 0 && !S_ISREG(self->sb.st_mode))) {
if (opened_path) {
efree(*opened_path);
zend_string_release(*opened_path);
*opened_path = NULL;
}
php_stream_close(ret);
@ -1018,7 +1011,6 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
}
close(fd);
}
efree(realpath);
if (persistent_id) {
efree(persistent_id);
}
@ -1028,7 +1020,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha
static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, const char *path, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC)
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path)) {
return NULL;
@ -1393,7 +1385,7 @@ PHPAPI php_stream_wrapper php_plain_files_wrapper = {
};
/* {{{ php_stream_fopen_with_path */
PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC)
PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path, int options STREAMS_DC)
{
/* code ripped off from fopen_wrappers.c */
char *pathbuf, *end;

16
main/streams/streams.c

@ -2015,13 +2015,13 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_
/* {{{ php_stream_open_wrapper_ex */
PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mode, int options,
char **opened_path, php_stream_context *context STREAMS_DC)
zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
const char *path_to_open;
int persistent = options & STREAM_OPEN_PERSISTENT;
char *resolved_path = NULL;
zend_string *resolved_path = NULL;
char *copy_of_path = NULL;
if (opened_path) {
@ -2036,7 +2036,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
if (options & USE_PATH) {
resolved_path = zend_resolve_path(path, (int)strlen(path));
if (resolved_path) {
path = resolved_path;
path = resolved_path->val;
/* we've found this file, don't re-check include_path or run realpath */
options |= STREAM_ASSUME_REALPATH;
options &= ~USE_PATH;
@ -2049,7 +2049,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
if (options & STREAM_USE_URL && (!wrapper || !wrapper->is_url)) {
php_error_docref(NULL, E_WARNING, "This function may only be used against URLs");
if (resolved_path) {
efree(resolved_path);
zend_string_release(resolved_path);
}
return NULL;
}
@ -2102,7 +2102,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
? PHP_STREAM_PREFER_STDIO : PHP_STREAM_NO_PREFERENCE)) {
case PHP_STREAM_UNCHANGED:
if (resolved_path) {
efree(resolved_path);
zend_string_release(resolved_path);
}
return stream;
case PHP_STREAM_RELEASED:
@ -2111,7 +2111,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
}
newstream->orig_path = pestrdup(path, persistent);
if (resolved_path) {
efree(resolved_path);
zend_string_release(resolved_path);
}
return newstream;
default:
@ -2141,7 +2141,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
if (stream == NULL && (options & REPORT_ERRORS)) {
php_stream_display_wrapper_errors(wrapper, path, "failed to open stream");
if (opened_path && *opened_path) {
efree(*opened_path);
zend_string_release(*opened_path);
*opened_path = NULL;
}
}
@ -2152,7 +2152,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod
}
#endif
if (resolved_path) {
efree(resolved_path);
zend_string_release(resolved_path);
}
return stream;
}

10
main/streams/userspace.c

@ -45,7 +45,7 @@ struct php_user_stream_wrapper {
php_stream_wrapper wrapper;
};
static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC);
static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context);
static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context);
static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context);
@ -53,7 +53,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int
static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context);
static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context);
static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC);
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
static php_stream_wrapper_ops user_stream_wops = {
user_wrapper_opener,
@ -325,7 +325,7 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
}
static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC)
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
php_userstream_data_t *us;
@ -385,7 +385,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
/* if the opened path is set, copy it out */
if (Z_ISREF(args[3]) && Z_TYPE_P(Z_REFVAL(args[3])) == IS_STRING && opened_path) {
*opened_path = estrndup(Z_STRVAL_P(Z_REFVAL(args[3])), Z_STRLEN_P(Z_REFVAL(args[3])));
*opened_path = zend_string_copy(Z_STR_P(Z_REFVAL(args[3])));
}
/* set wrapper data to be a reference to our object */
@ -415,7 +415,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
}
static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, char **opened_path, php_stream_context *context STREAMS_DC)
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
php_userstream_data_t *us;

Loading…
Cancel
Save