From: Wez Furlong Date: Sat, 16 Mar 2002 18:42:42 +0000 (+0000) Subject: Fix some issues with gzFile and fsockopen. X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~1336 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d0c53eecf5e720dd73d14c602a3df9c752e3a67;p=php Fix some issues with gzFile and fsockopen. --- diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 530dcdd21a..e3d3342f27 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -159,7 +159,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) ZVAL_STRING(zerrno, "", 1); } - if (port != -1) { /* connect to a host */ + if (port > 0) { /* connect to a host */ enum php_sslflags_t { php_ssl_none, php_ssl_v23, php_ssl_tls }; enum php_sslflags_t ssl_flags; struct { @@ -195,6 +195,11 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) #endif stream = php_stream_sock_open_host(host, port, socktype, (int)timeout, persistent); + if (stream == NULL) { + zend_error(E_WARNING, "%s(): unable to connect to %s:%d", + get_active_function_name(TSRMLS_C), host, port); + } + #if HAVE_OPENSSL_EXT if (stream) { int ssl_ret = FAILURE; diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index a0c54fbd81..44edcbdcd3 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -257,7 +257,7 @@ static gzFile php_gzopen_wrapper(char *path, char *mode, int options TSRMLS_DC) stream = php_stream_open_wrapper(path, mode, options | REPORT_ERRORS, NULL TSRMLS_CC); if (stream) { - if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_TRY_HARD, (void**)&fd, 1)) + if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD|PHP_STREAM_CAST_TRY_HARD, (void**)&fd, 1)) { gzFile ret = gzdopen(fd, mode); if (ret) { @@ -302,8 +302,8 @@ PHP_FUNCTION(gzfile) convert_to_string_ex(filename); /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */ - stream = php_stream_gzopen(Z_STRVAL_PP(filename), "r", use_include_path|ENFORCE_SAFE_MODE, NULL TSRMLS_CC); - if (!stream) { + stream = php_stream_gzopen(Z_STRVAL_PP(filename), "rb", use_include_path|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL TSRMLS_CC); + if (stream == NULL) { php_error(E_WARNING,"gzFile(\"%s\") - %s",Z_STRVAL_PP(filename),strerror(errno)); RETURN_FALSE; } diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c index 31589f824b..5d3129f843 100644 --- a/ext/zlib/zlib_fopen_wrapper.c +++ b/ext/zlib/zlib_fopen_wrapper.c @@ -86,10 +86,9 @@ php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened php_stream *stream = NULL; self = emalloc(sizeof(*self)); - - while(*path != ':') - path++; - path++; + + if (strncmp("zlib:", path, 5) == 0) + path += 5; self->stream = php_stream_open_wrapper(path, mode, options, opened_path TSRMLS_CC);