mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fixes to various stream cast on win64
This fixes further issues on win64 with casts from the streams. Sockets/descriptors handling was unitized. This has an impact only on win64, php_socket_t otherwise can be feed back to int datatype.
This commit is contained in:
parent
a6f7fca637
commit
62f6c5853f
6 changed files with 23 additions and 24 deletions
|
@ -31,6 +31,7 @@
|
||||||
#include "ext/standard/file.h"
|
#include "ext/standard/file.h"
|
||||||
#include "ext/standard/info.h"
|
#include "ext/standard/info.h"
|
||||||
#include "ext/standard/php_string.h"
|
#include "ext/standard/php_string.h"
|
||||||
|
#include "main/php_network.h"
|
||||||
|
|
||||||
/* for fileno() */
|
/* for fileno() */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -245,7 +246,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
|
||||||
stream = php_stream_open_wrapper(path, mode, options | STREAM_WILL_CAST, opened_path);
|
stream = php_stream_open_wrapper(path, mode, options | STREAM_WILL_CAST, opened_path);
|
||||||
|
|
||||||
if (stream) {
|
if (stream) {
|
||||||
int fd;
|
php_socket_t fd;
|
||||||
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) {
|
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) {
|
||||||
bz_file = BZ2_bzdopen(fd, mode);
|
bz_file = BZ2_bzdopen(fd, mode);
|
||||||
}
|
}
|
||||||
|
@ -394,7 +395,7 @@ static PHP_FUNCTION(bzopen)
|
||||||
NULL);
|
NULL);
|
||||||
} else if (Z_TYPE_PP(file) == IS_RESOURCE) {
|
} else if (Z_TYPE_PP(file) == IS_RESOURCE) {
|
||||||
/* If it is a resource, than its a stream resource */
|
/* If it is a resource, than its a stream resource */
|
||||||
int fd;
|
php_socket_t fd;
|
||||||
int stream_mode_len;
|
int stream_mode_len;
|
||||||
|
|
||||||
php_stream_from_zval(stream, file);
|
php_stream_from_zval(stream, file);
|
||||||
|
|
|
@ -49,6 +49,9 @@ FILE_RCSID("@(#)$File: funcs.c,v 1.67 2014/02/12 23:20:53 christos Exp $")
|
||||||
# define SIZE_MAX ((size_t) -1)
|
# define SIZE_MAX ((size_t) -1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "php.h"
|
||||||
|
#include "main/php_network.h"
|
||||||
|
|
||||||
#ifndef PREG_OFFSET_CAPTURE
|
#ifndef PREG_OFFSET_CAPTURE
|
||||||
# define PREG_OFFSET_CAPTURE (1<<8)
|
# define PREG_OFFSET_CAPTURE (1<<8)
|
||||||
#endif
|
#endif
|
||||||
|
@ -218,7 +221,7 @@ file_buffer(struct magic_set *ms, php_stream *stream, const char *inname, const
|
||||||
|
|
||||||
/* Check if we have a CDF file */
|
/* Check if we have a CDF file */
|
||||||
if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) {
|
if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0) {
|
||||||
int fd;
|
php_socket_t fd;
|
||||||
TSRMLS_FETCH();
|
TSRMLS_FETCH();
|
||||||
if (stream && SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **)&fd, 0)) {
|
if (stream && SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **)&fd, 0)) {
|
||||||
if ((m = file_trycdf(ms, fd, ubuf, nb)) != 0) {
|
if ((m = file_trycdf(ms, fd, ubuf, nb)) != 0) {
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
#include "php_globals.h"
|
#include "php_globals.h"
|
||||||
#include "SAPI.h"
|
#include "SAPI.h"
|
||||||
|
#include "main/php_network.h"
|
||||||
|
|
||||||
#ifdef NETWARE
|
#ifdef NETWARE
|
||||||
#include <proc.h>
|
#include <proc.h>
|
||||||
|
@ -556,7 +557,7 @@ PHP_FUNCTION(proc_open)
|
||||||
if (Z_TYPE_PP(descitem) == IS_RESOURCE) {
|
if (Z_TYPE_PP(descitem) == IS_RESOURCE) {
|
||||||
/* should be a stream - try and dup the descriptor */
|
/* should be a stream - try and dup the descriptor */
|
||||||
php_stream *stream;
|
php_stream *stream;
|
||||||
int fd;
|
php_socket_t fd;
|
||||||
|
|
||||||
php_stream_from_zval(stream, descitem);
|
php_stream_from_zval(stream, descitem);
|
||||||
|
|
||||||
|
@ -629,7 +630,7 @@ PHP_FUNCTION(proc_open)
|
||||||
|
|
||||||
} else if (strcmp(Z_STRVAL_PP(ztype), "file") == 0) {
|
} else if (strcmp(Z_STRVAL_PP(ztype), "file") == 0) {
|
||||||
zval **zfile, **zmode;
|
zval **zfile, **zmode;
|
||||||
int fd;
|
php_socket_t fd;
|
||||||
php_stream *stream;
|
php_stream *stream;
|
||||||
|
|
||||||
descriptors[ndesc].mode = DESC_FILE;
|
descriptors[ndesc].mode = DESC_FILE;
|
||||||
|
|
|
@ -613,7 +613,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
|
||||||
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
|
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
|
||||||
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
|
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
|
||||||
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
|
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
|
||||||
int tmp_fd;
|
php_socket_t this_fd;
|
||||||
|
|
||||||
php_stream_from_zval_no_verify(stream, elem);
|
php_stream_from_zval_no_verify(stream, elem);
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
|
@ -624,9 +624,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
|
||||||
* when casting. It is only used here so that the buffered data warning
|
* when casting. It is only used here so that the buffered data warning
|
||||||
* is not displayed.
|
* is not displayed.
|
||||||
* */
|
* */
|
||||||
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && tmp_fd != -1) {
|
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd != -1) {
|
||||||
|
|
||||||
php_socket_t this_fd = (php_socket_t)tmp_fd;
|
|
||||||
|
|
||||||
PHP_SAFE_FD_SET(this_fd, fds);
|
PHP_SAFE_FD_SET(this_fd, fds);
|
||||||
|
|
||||||
|
@ -660,10 +658,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
|
||||||
char *key;
|
char *key;
|
||||||
uint key_len;
|
uint key_len;
|
||||||
ulong num_ind;
|
ulong num_ind;
|
||||||
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
|
php_socket_t this_fd;
|
||||||
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
|
|
||||||
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
|
|
||||||
int tmp_fd;
|
|
||||||
|
|
||||||
|
|
||||||
type = zend_hash_get_current_key_ex(Z_ARRVAL_P(stream_array),
|
type = zend_hash_get_current_key_ex(Z_ARRVAL_P(stream_array),
|
||||||
|
@ -682,10 +677,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
|
||||||
* when casting. It is only used here so that the buffered data warning
|
* when casting. It is only used here so that the buffered data warning
|
||||||
* is not displayed.
|
* is not displayed.
|
||||||
*/
|
*/
|
||||||
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && tmp_fd != -1) {
|
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd != SOCK_ERR) {
|
||||||
|
|
||||||
php_socket_t this_fd = (php_socket_t)tmp_fd;
|
|
||||||
|
|
||||||
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
|
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
|
||||||
if (type == HASH_KEY_IS_LONG) {
|
if (type == HASH_KEY_IS_LONG) {
|
||||||
zend_hash_index_update(new_hash, num_ind, (void *)elem, sizeof(zval *), (void **)&dest_elem);
|
zend_hash_index_update(new_hash, num_ind, (void *)elem, sizeof(zval *), (void **)&dest_elem);
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include "php_zlib.h"
|
#include "php_zlib.h"
|
||||||
#include "fopen_wrappers.h"
|
#include "fopen_wrappers.h"
|
||||||
|
|
||||||
|
#include "main/php_network.h"
|
||||||
|
|
||||||
struct php_gz_stream_data_t {
|
struct php_gz_stream_data_t {
|
||||||
gzFile gz_file;
|
gzFile gz_file;
|
||||||
php_stream *stream;
|
php_stream *stream;
|
||||||
|
@ -129,7 +131,7 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, con
|
||||||
innerstream = php_stream_open_wrapper_ex(path, mode, STREAM_MUST_SEEK | options | STREAM_WILL_CAST, opened_path, context);
|
innerstream = php_stream_open_wrapper_ex(path, mode, STREAM_MUST_SEEK | options | STREAM_WILL_CAST, opened_path, context);
|
||||||
|
|
||||||
if (innerstream) {
|
if (innerstream) {
|
||||||
int fd;
|
php_socket_t fd;
|
||||||
|
|
||||||
if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) {
|
if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) {
|
||||||
self = emalloc(sizeof(*self));
|
self = emalloc(sizeof(*self));
|
||||||
|
|
|
@ -482,7 +482,7 @@ static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t *
|
||||||
|
|
||||||
static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
|
static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
|
||||||
{
|
{
|
||||||
int fd;
|
php_socket_t fd;
|
||||||
php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract;
|
php_stdio_stream_data *data = (php_stdio_stream_data*) stream->abstract;
|
||||||
|
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
|
@ -506,31 +506,31 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
|
||||||
}
|
}
|
||||||
|
|
||||||
*(FILE**)ret = data->file;
|
*(FILE**)ret = data->file;
|
||||||
data->fd = -1;
|
data->fd = SOCK_ERR;
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
||||||
case PHP_STREAM_AS_FD_FOR_SELECT:
|
case PHP_STREAM_AS_FD_FOR_SELECT:
|
||||||
PHP_STDIOP_GET_FD(fd, data);
|
PHP_STDIOP_GET_FD(fd, data);
|
||||||
if (fd < 0) {
|
if (SOCK_ERR == fd) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
*(int*)ret = fd;
|
*(php_socket_t *)ret = fd;
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
||||||
case PHP_STREAM_AS_FD:
|
case PHP_STREAM_AS_FD:
|
||||||
PHP_STDIOP_GET_FD(fd, data);
|
PHP_STDIOP_GET_FD(fd, data);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (SOCK_ERR == fd) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
if (data->file) {
|
if (data->file) {
|
||||||
fflush(data->file);
|
fflush(data->file);
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
*(int*)ret = fd;
|
*(php_socket_t *)ret = fd;
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue