Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
#include "zend_enum.h"
#include "zend_closures.h"
#include "Optimizer/zend_optimizer.h"
#include "php.h"
#include "php_globals.h"

// FIXME: Breaks the declaration of the function below
#undef zenderror
Expand Down
4 changes: 2 additions & 2 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ PHP_FUNCTION(finfo_file)
zend_argument_must_not_be_empty_error(hasThis() ? 1 : 2);
RETURN_THROWS();
}
php_stream_context *context = php_stream_context_from_zval(zcontext, false);
php_stream_context *context = php_stream_context_from_zval_or_default(zcontext);
if (!context) {
RETURN_THROWS();
}
Expand Down Expand Up @@ -424,7 +424,7 @@ PHP_FUNCTION(mime_content_type)

const char *ret_val;
if (path) {
php_stream_context *context = php_stream_context_get_default(false);
php_stream_context *context = php_stream_context_get_default();
ret_val = php_fileinfo_from_path(magic, path, context);
} else {
/* remember stream position for restoration */
Expand Down
6 changes: 3 additions & 3 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static void php_hash_do_hash(
zend_argument_value_error(2, "must not contain any null bytes");
RETURN_THROWS();
}
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, php_stream_context_get_default());
if (!stream) {
/* Stream will report errors opening file */
RETURN_FALSE;
Expand Down Expand Up @@ -499,7 +499,7 @@ static void php_hash_do_hash_hmac(
zend_argument_value_error(2, "must not contain any null bytes");
RETURN_THROWS();
}
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, php_stream_context_get_default());
if (!stream) {
/* Stream will report errors opening file */
RETURN_FALSE;
Expand Down Expand Up @@ -743,7 +743,7 @@ PHP_FUNCTION(hash_update_file)

hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
PHP_HASHCONTEXT_VERIFY(hash);
context = php_stream_context_from_zval(zcontext, 0);
context = php_stream_context_from_zval_or_default(zcontext);

stream = php_stream_open_wrapper_ex(ZSTR_VAL(filename), "rb", REPORT_ERRORS, NULL, context);
if (!stream) {
Expand Down
9 changes: 7 additions & 2 deletions ext/libxml/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ static PHP_GINIT_FUNCTION(libxml)

PHP_LIBXML_API php_stream_context *php_libxml_get_stream_context(void)
{
return php_stream_context_from_zval(Z_ISUNDEF(LIBXML(stream_context)) ? NULL : &LIBXML(stream_context), false);
php_stream_context *context = php_stream_context_get_default();
if (!Z_ISUNDEF(LIBXML(stream_context))) {
context = php_stream_context_from_zval(&LIBXML(stream_context));
}
return context;
}

/* Channel libxml file io layer through the PHP streams subsystem.
Expand Down Expand Up @@ -1105,7 +1109,8 @@ PHP_FUNCTION(libxml_set_streams_context)
Z_PARAM_RESOURCE(arg)
ZEND_PARSE_PARAMETERS_END();

if (php_stream_context_from_zval(arg, true) != NULL) {
php_stream_context *context = php_stream_context_from_zval(arg);
if (context != NULL) {
if (!Z_ISUNDEF(LIBXML(stream_context))) {
zval_ptr_dtor(&LIBXML(stream_context));
}
Expand Down
2 changes: 1 addition & 1 deletion ext/libxml/php_libxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern zend_module_entry libxml_module_entry;
#define LIBXML_NS_TAG_HOOK 1

ZEND_BEGIN_MODULE_GLOBALS(libxml)
zval stream_context;
zval stream_context; // TODO: Use php_stream_context* directly?
smart_str error_buffer;
zend_llist *error_list;
zend_fcall_info_cache entity_loader_callback;
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo_pgsql/pgsql_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ void pgsqlCopyFromFile_internal(INTERNAL_FUNCTION_PARAMETERS)
PDO_CONSTRUCT_CHECK;
PDO_DBH_CLEAR_ERR();

stream = php_stream_open_wrapper_ex(filename, "rb", 0, NULL, FG(default_context));
stream = php_stream_open_wrapper_ex(filename, "rb", 0, NULL, php_stream_context_get_default());
if (!stream) {
pdo_pgsql_error_msg(dbh, PGRES_FATAL_ERROR, "Unable to open the file");
PDO_HANDLE_DBH_ERR();
Expand Down Expand Up @@ -966,7 +966,7 @@ void pgsqlCopyToFile_internal(INTERNAL_FUNCTION_PARAMETERS)

H = (pdo_pgsql_db_handle *)dbh->driver_data;

stream = php_stream_open_wrapper_ex(filename, "wb", 0, NULL, FG(default_context));
stream = php_stream_open_wrapper_ex(filename, "wb", 0, NULL, php_stream_context_get_default());
if (!stream) {
pdo_pgsql_error_msg(dbh, PGRES_FATAL_ERROR, "Unable to open the file for writing");
PDO_HANDLE_DBH_ERR();
Expand Down
8 changes: 4 additions & 4 deletions ext/phar/func_interceptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PHP_FUNCTION(phar_opendir) /* {{{ */
zend_string_release_ex(entry, false);
zend_string_release_ex(arch, false);
if (zcontext) {
context = php_stream_context_from_zval(zcontext, 0);
context = php_stream_context_from_zval(zcontext);
}
stream = php_stream_opendir(name, REPORT_ERRORS, context);
efree(name);
Expand Down Expand Up @@ -185,7 +185,7 @@ PHP_FUNCTION(phar_file_get_contents) /* {{{ */
php_stream *stream;

if (zcontext) {
context = php_stream_context_from_zval(zcontext, 0);
context = php_stream_context_from_zval(zcontext);
}
stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context);

Expand Down Expand Up @@ -245,7 +245,7 @@ PHP_FUNCTION(phar_readfile) /* {{{ */
}

php_stream *stream;
php_stream_context *context = php_stream_context_from_zval(zcontext, 0);
php_stream_context *context = php_stream_context_from_zval_or_default(zcontext);

stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), "rb", 0 | REPORT_ERRORS, NULL, context);

Expand Down Expand Up @@ -292,7 +292,7 @@ PHP_FUNCTION(phar_fopen) /* {{{ */
}

php_stream *stream;
php_stream_context *context = php_stream_context_from_zval(zcontext, 0);
php_stream_context *context = php_stream_context_from_zval_or_default(zcontext);

stream = php_stream_open_wrapper_ex(ZSTR_VAL(name), mode, 0 | REPORT_ERRORS, NULL, context);

Expand Down
2 changes: 1 addition & 1 deletion ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ bool make_http_soap_request(

tmp = Z_CLIENT_STREAM_CONTEXT_P(this_ptr);
if (Z_TYPE_P(tmp) == IS_RESOURCE) {
context = php_stream_context_from_zval(tmp, 0);
context = php_stream_context_from_zval(tmp);
}

if (context &&
Expand Down
4 changes: 2 additions & 2 deletions ext/soap/php_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void sdl_set_uri_credentials(sdlCtx *ctx, char *uri)
return;
}
zval *context_ptr = &context;
ctx->context = php_stream_context_from_zval(context_ptr, 1);
ctx->context = php_stream_context_from_zval(context_ptr);

if (!ctx->context) {
return;
Expand Down Expand Up @@ -3396,7 +3396,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl)
if (instanceof_function(Z_OBJCE_P(this_ptr), soap_class_entry)) {
tmp = Z_CLIENT_STREAM_CONTEXT_P(this_ptr);
if (Z_TYPE_P(tmp) == IS_RESOURCE) {
context = php_stream_context_from_zval(tmp, 0);
context = php_stream_context_from_zval(tmp);
/* Share a reference with new_context down below.
* For new contexts, the reference is only in new_context so that doesn't need extra refcounting. */
GC_ADDREF(context->res);
Expand Down
4 changes: 2 additions & 2 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ PHP_METHOD(SoapServer, handle)
*/

sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
php_stream_context *context = php_stream_context_from_zval(NULL, false);
php_stream_context *context = php_stream_context_get_default();
php_stream *stream = php_stream_open_wrapper_ex(service->sdl->source, "rb", REPORT_ERRORS, NULL, context);
if (stream) {
php_stream_passthru(stream);
Expand Down Expand Up @@ -2275,7 +2275,7 @@ PHP_METHOD(SoapClient, __construct)

if ((tmp = zend_hash_str_find(ht, "stream_context", sizeof("stream_context")-1)) != NULL &&
Z_TYPE_P(tmp) == IS_RESOURCE) {
context = php_stream_context_from_zval(tmp, 1);
context = php_stream_context_from_zval(tmp);
Z_ADDREF_P(tmp);
} else {
context = php_stream_context_alloc();
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_string *
bool skip_dots = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_SKIPDOTS);

intern->type = SPL_FS_DIR;
intern->u.dir.dirp = php_stream_opendir(ZSTR_VAL(path), REPORT_ERRORS, FG(default_context));
intern->u.dir.dirp = php_stream_opendir(ZSTR_VAL(path), REPORT_ERRORS, php_stream_context_get_default());

if (intern->u.dir.dirp) {
/* we prevent potential UAF with conflicting explicit fclose(), relying on the object destructor for this */
Expand Down Expand Up @@ -328,7 +328,7 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
return FAILURE;
}

intern->u.file.context = php_stream_context_from_zval(intern->u.file.zcontext, 0);
intern->u.file.context = php_stream_context_from_zval_or_default(intern->u.file.zcontext);
intern->u.file.stream = php_stream_open_wrapper_ex(ZSTR_VAL(intern->file_name), ZSTR_VAL(intern->u.file.open_mode), (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, NULL, intern->u.file.context);

if (!ZSTR_LEN(intern->file_name) || !intern->u.file.stream) {
Expand Down
2 changes: 0 additions & 2 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ PHP_RINIT_FUNCTION(basic) /* {{{ */
/* Initialize memory for last http headers */
ZVAL_UNDEF(&BG(last_http_headers));

/* Setup default context */
FG(default_context) = NULL;
return SUCCESS;
}
/* }}} */
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject)
Z_PARAM_RESOURCE_OR_NULL(zcontext)
ZEND_PARSE_PARAMETERS_END();

context = php_stream_context_from_zval(zcontext, 0);
context = php_stream_context_from_zval_or_default(zcontext);

dirp = php_stream_opendir(dirname, REPORT_ERRORS, context);

Expand Down Expand Up @@ -579,7 +579,7 @@ PHP_FUNCTION(scandir)
}

if (zcontext) {
context = php_stream_context_from_zval(zcontext, 0);
context = php_stream_context_from_zval_or_default(zcontext);
}

if (flags == PHP_SCANDIR_SORT_ASCENDING) {
Expand Down
Loading
Loading