Skip to content
Draft
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: 1 addition & 1 deletion ext/bz2/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ PHP_FUNCTION(bzopen)
php_socket_t fd;
size_t stream_mode_len;

php_stream_from_zval(stream, file);
php_stream_from_res(stream, Z_RES_P(file));
stream_mode_len = strlen(stream->mode);

char primary_stream_mode;
Expand Down
6 changes: 3 additions & 3 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 @@ -402,7 +402,7 @@ PHP_FUNCTION(mime_content_type)
break;

case IS_RESOURCE:
php_stream_from_zval(stream, path_or_stream);
php_stream_from_res(stream, Z_RES_P(path_or_stream));
break;

default:
Expand All @@ -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
2 changes: 1 addition & 1 deletion ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4540,7 +4540,7 @@ static gdIOCtx *create_output_context(zval *to_zval, uint32_t arg_num) {
ZEND_ASSERT(arg_num > 0);

if (Z_TYPE_P(to_zval) == IS_RESOURCE) {
php_stream_from_zval_no_verify(stream, to_zval);
php_stream_from_res_no_verify(stream, Z_RES_P(to_zval));
if (stream == NULL) {
return NULL;
}
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
2 changes: 1 addition & 1 deletion ext/pdo/pdo_sql_parser.re
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ safe:
if (param->param_type == PDO_PARAM_LOB && Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm;

php_stream_from_zval_no_verify(stm, parameter);
php_stream_from_res_no_verify(stm, Z_RES_P(parameter));
if (stm) {
zend_string *buf;

Expand Down
2 changes: 1 addition & 1 deletion ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, enum pdo
} else if (Z_TYPE_P(dest) == IS_RESOURCE) {
/* Convert LOB stream to string */
php_stream *stream;
php_stream_from_zval_no_verify(stream, dest);
php_stream_from_res_no_verify(stream, Z_RES_P(dest));
zend_string *str = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0);
zval_ptr_dtor_nogc(dest);
if (str == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_firebird/firebird_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ static int pdo_firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm = NULL;

php_stream_from_zval_no_verify(stm, parameter);
php_stream_from_res_no_verify(stm, Z_RES_P(parameter));
if (stm) {
zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0);
zval_ptr_dtor(parameter);
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_mysql/mysql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
}
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm = NULL;
php_stream_from_zval_no_verify(stm, parameter);
php_stream_from_res_no_verify(stm, Z_RES_P(parameter));
if (stm) {
zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0);
zval_ptr_dtor(parameter);
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
2 changes: 1 addition & 1 deletion ext/pdo_pgsql/pgsql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB &&
Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm;
php_stream_from_zval_no_verify(stm, parameter);
php_stream_from_res_no_verify(stm, Z_RES_P(parameter));
if (stm) {
if (php_stream_is(stm, &pdo_pgsql_lob_stream_ops)) {
struct pdo_pgsql_lob_self *self = (struct pdo_pgsql_lob_self*)stm->abstract;
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo_sqlite/sqlite_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
}
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm = NULL;
php_stream_from_zval_no_verify(stm, parameter);
php_stream_from_res_no_verify(stm, Z_RES_P(parameter));
if (stm) {
zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0);
zval_ptr_dtor(parameter);
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_or_default(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_or_default(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
4 changes: 2 additions & 2 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
case IS_STRING:
break;
case IS_RESOURCE:
php_stream_from_zval_no_verify(fp, value);
php_stream_from_res_no_verify(fp, Z_RES_P(value));

if (!fp) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Iterator %pS returned an invalid stream handle", ce->name);
Expand Down Expand Up @@ -2849,7 +2849,7 @@ PHP_METHOD(Phar, setStub)
RETURN_THROWS();
}

if ((php_stream_from_zval_no_verify(stream, zstub)) != NULL) {
if ((php_stream_from_res_no_verify(stream, Z_RES_P(zstub))) != NULL) {
if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%pS\" is persistent, unable to copy on write", phar_obj->archive->fname);
RETURN_THROWS();
Expand Down
10 changes: 5 additions & 5 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ PHP_FUNCTION(posix_ctermid)
/* }}} */

/* Checks if the provides resource is a stream and if it provides a file descriptor */
static zend_result php_posix_stream_get_fd(zval *zfp, zend_long *ret) /* {{{ */
static zend_result php_posix_stream_get_fd(zend_resource *zfp, zend_long *ret) /* {{{ */
{
php_stream *stream;

php_stream_from_zval_no_verify(stream, zfp);
php_stream_from_res_no_verify(stream, zfp);

if (stream == NULL) {
return FAILURE;
Expand Down Expand Up @@ -481,7 +481,7 @@ PHP_FUNCTION(posix_ttyname)
ZEND_PARSE_PARAMETERS_END();

if (Z_TYPE_P(z_fd) == IS_RESOURCE) {
if (php_posix_stream_get_fd(z_fd, &fd) == FAILURE) {
if (php_posix_stream_get_fd(Z_RES_P(z_fd), &fd) == FAILURE) {
RETURN_FALSE;
}
} else {
Expand Down Expand Up @@ -543,7 +543,7 @@ PHP_FUNCTION(posix_isatty)
ZEND_PARSE_PARAMETERS_END();

if (Z_TYPE_P(z_fd) == IS_RESOURCE) {
if (php_posix_stream_get_fd(z_fd, &fd) == FAILURE) {
if (php_posix_stream_get_fd(Z_RES_P(z_fd), &fd) == FAILURE) {
RETURN_FALSE;
}
} else {
Expand Down Expand Up @@ -1363,7 +1363,7 @@ PHP_FUNCTION(posix_fpathconf)
ZEND_PARSE_PARAMETERS_END();

if (Z_TYPE_P(z_fd) == IS_RESOURCE) {
if (php_posix_stream_get_fd(z_fd, &fd) == FAILURE) {
if (php_posix_stream_get_fd(Z_RES_P(z_fd), &fd) == FAILURE) {
RETURN_FALSE;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ bool make_http_soap_request(

tmp = Z_CLIENT_HTTPSOCKET_P(this_ptr);
if (Z_TYPE_P(tmp) == IS_RESOURCE) {
php_stream_from_zval_no_verify(stream,tmp);
php_stream_from_res_no_verify(stream, Z_RES_P(tmp));
tmp = Z_CLIENT_USE_PROXY_P(this_ptr);
if (Z_TYPE_P(tmp) == IS_LONG) {
use_proxy = Z_LVAL_P(tmp);
Expand All @@ -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_or_default(tmp);
}

if (context &&
Expand Down
2 changes: 1 addition & 1 deletion ext/soap/php_sdl.c
Original file line number Diff line number Diff line change
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_or_default(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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ PHP_FUNCTION(socket_import_stream)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(zstream)
ZEND_PARSE_PARAMETERS_END();
php_stream_from_zval(stream, zstream);
php_stream_from_res(stream, Z_RES_P(zstream));

if (php_stream_cast(stream, PHP_STREAM_AS_SOCKETD, (void**)&socket, 1) == FAILURE) {
/* error supposedly already shown */
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: 1 addition & 1 deletion ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */
php_stream *stream = NULL;
zend_string *buffer = NULL;
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream_from_zval_no_verify(stream, parameter);
php_stream_from_res_no_verify(stream, Z_RES_P(parameter));
if (stream == NULL) {
php_sqlite3_error(stmt_obj->db_obj, 0, "Unable to read stream for parameter %ld", param->param_number);
return FAILURE;
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