summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/SAPI.h5
-rw-r--r--main/fopen_wrappers.c2
-rw-r--r--main/main.c4
-rw-r--r--main/php.h2
-rw-r--r--main/php_ini.c5
-rw-r--r--main/php_stdint.h206
-rw-r--r--main/php_streams.h44
-rw-r--r--main/php_variables.c2
-rw-r--r--main/rfc1867.c50
-rw-r--r--main/snprintf.h6
-rw-r--r--main/spprintf.h2
-rw-r--r--main/streams/cast.c2
-rw-r--r--main/streams/glob_wrapper.c10
-rw-r--r--main/streams/memory.c8
-rw-r--r--main/streams/php_stream_plain_wrapper.h2
-rw-r--r--main/streams/php_stream_transport.h16
-rw-r--r--main/streams/plain_wrapper.c21
-rw-r--r--main/streams/streams.c66
-rw-r--r--main/streams/transports.c10
-rw-r--r--main/streams/userspace.c38
-rw-r--r--main/streams/xp_socket.c8
21 files changed, 380 insertions, 129 deletions
diff --git a/main/SAPI.h b/main/SAPI.h
index 92b7329dbc..6fc60c8865 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -27,6 +27,7 @@
#include "zend_operators.h"
#ifdef PHP_WIN32
#include "win95nt.h"
+#include "win32/php_stdint.h"
#endif
#include <sys/stat.h>
@@ -82,7 +83,7 @@ typedef struct {
char *post_data, *raw_post_data;
char *cookie_data;
long content_length;
- uint post_data_length, raw_post_data_length;
+ int64_t post_data_length, raw_post_data_length;
char *path_translated;
char *request_uri;
@@ -119,7 +120,7 @@ typedef struct _sapi_globals_struct {
void *server_context;
sapi_request_info request_info;
sapi_headers_struct sapi_headers;
- int read_post_bytes;
+ int64_t read_post_bytes;
unsigned char headers_sent;
struct stat global_stat;
char *default_mimetype;
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 6f11cf3f32..eb33ac7ba1 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -475,7 +475,7 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c
char resolved_path[MAXPATHLEN];
char trypath[MAXPATHLEN];
const char *ptr, *end, *p;
- char *actual_path;
+ const char *actual_path;
php_stream_wrapper *wrapper;
if (!filename || CHECK_NULL_PATH(filename, filename_length)) {
diff --git a/main/main.c b/main/main.c
index d11ef84b34..2f56afa03a 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1531,7 +1531,7 @@ int php_request_startup(TSRMLS_D)
int retval = SUCCESS;
#ifdef HAVE_DTRACE
- DTRACE_REQUEST_STARTUP(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), SAFE_FILENAME(SG(request_info).request_method));
+ DTRACE_REQUEST_STARTUP(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), (char *)SAFE_FILENAME(SG(request_info).request_method));
#endif /* HAVE_DTRACE */
#ifdef PHP_WIN32
@@ -1841,7 +1841,7 @@ void php_request_shutdown(void *dummy)
#endif
#ifdef HAVE_DTRACE
- DTRACE_REQUEST_SHUTDOWN(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), SAFE_FILENAME(SG(request_info).request_method));
+ DTRACE_REQUEST_SHUTDOWN(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), (char *)SAFE_FILENAME(SG(request_info).request_method));
#endif /* HAVE_DTRACE */
}
/* }}} */
diff --git a/main/php.h b/main/php.h
index 7c1f8fd0c7..17ac8b4fd2 100644
--- a/main/php.h
+++ b/main/php.h
@@ -180,6 +180,8 @@ typedef unsigned int socklen_t;
# endif
#endif
+#include "php_stdint.h"
+
#include "zend_hash.h"
#include "zend_alloc.h"
#include "zend_stack.h"
diff --git a/main/php_ini.c b/main/php_ini.c
index cb2c7ea808..e9529a2d29 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -802,7 +802,12 @@ PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC)
char path_bak[MAXPATHLEN];
#endif
+#if PHP_WIN32
+ /* MAX_PATH is \0-terminated, path_len == MAXPATHLEN would overrun path_bak */
+ if (path_len >= MAXPATHLEN) {
+#else
if (path_len > MAXPATHLEN) {
+#endif
return;
}
diff --git a/main/php_stdint.h b/main/php_stdint.h
new file mode 100644
index 0000000000..87edb0fde0
--- /dev/null
+++ b/main/php_stdint.h
@@ -0,0 +1,206 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Michael Wallner <mike@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHP_STDINT_H
+#define PHP_STDINT_H
+
+#if defined(_MSC_VER)
+/* Make sure the regular stdint.h wasn't included already and prevent it to be
+ included afterwards. Though if some other library needs some stuff from
+ stdint.h included afterwards and misses it, we'd have to extend ours. On
+ the other hand, if stdint.h was included before, some conflicts might
+ happen so we'd likewise have to fix ours. */
+# if !defined(_STDINT)
+# define _STDINT
+# include "win32/php_stdint.h"
+# endif
+# define HAVE_INT8_T 1
+# define HAVE_UINT8_T 1
+# define HAVE_INT16_T 1
+# define HAVE_UINT16_T 1
+# define HAVE_INT32_T 1
+# define HAVE_UINT32_T 1
+# define HAVE_INT64_T 1
+# define HAVE_UINT64_T 1
+#else
+
+#include "php_config.h"
+
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
+#ifndef HAVE_INT8_T
+# ifdef HAVE_INT8
+typedef int8 int8_t;
+# else
+typedef signed char int8_t;
+# endif
+#endif
+
+#ifndef INT8_C
+# define INT8_C(c) c
+#endif
+
+#ifndef HAVE_UINT8_T
+# ifdef HAVE_UINT8
+typedef uint8 uint8_t
+# elif HAVE_U_INT8_T
+typedef u_int8_t uint8_t;
+# else
+typedef unsigned char uint8_t;
+# endif
+#endif
+
+#ifndef UINT8_C
+# define UINT8_C(c) c
+#endif
+
+#ifndef HAVE_INT16_T
+# ifdef HAVE_INT16
+typedef int16 int16_t;
+# elif SIZEOF_SHORT >= 2
+typedef signed short int16_t;
+# else
+# error "No suitable 16bit integer type found"
+# endif
+#endif
+
+#ifndef INT16_C
+# define INT16_C(c) c
+#endif
+
+#ifndef HAVE_UINT16_T
+# ifdef HAVE_UINT16
+typedef uint16 uint16_t
+# elif HAVE_U_INT16_T
+typedef u_int16_t uint16_t;
+# elif SIZEOF_SHORT >= 2
+typedef unsigned short uint16_t;
+# else
+# error "No suitable 16bit integer type found"
+# endif
+#endif
+
+#ifndef UINT16_C
+# define UINT16_C(c) c
+#endif
+
+#ifndef HAVE_INT32_T
+# ifdef HAVE_INT32
+typedef int32 int32_t;
+# elif SIZEOF_INT >= 4
+typedef int int32_t;
+# elif SIZEOF_LONG >= 4
+typedef long int32_t;
+# else
+# error "No suitable 32bit integer type found"
+# endif
+#endif
+
+#ifndef INT32_C
+# define INT32_C(c) c
+#endif
+
+#ifndef HAVE_UINT32_T
+# ifdef HAVE_UINT32
+typedef uint32 uint32_t
+# elif HAVE_U_INT32_T
+typedef u_int32_t uint32_t;
+# elif SIZEOF_INT >= 4
+typedef unsigned int uint32_t;
+# elif SIZEOF_LONG >= 4
+typedef unsigned long uint32_t;
+# else
+# error "No suitable 32bit integer type found"
+# endif
+#endif
+
+#ifndef UINT32_C
+# define UINT32_C(c) c ## U
+#endif
+
+#ifndef HAVE_INT64_T
+# ifdef HAVE_INT64
+typedef int64 int64_t;
+# elif SIZEOF_INT >= 8
+typedef int int64_t;
+# elif SIZEOF_LONG >= 8
+typedef long int64_t;
+# elif SIZEOF_LONG_LONG >= 8
+typedef long long int64_t;
+# else
+# error "No suitable 64bit integer type found"
+# endif
+#endif
+
+#ifndef INT64_C
+# if SIZEOF_INT >= 8
+# define INT64_C(c) c
+# elif SIZEOF_LONG >= 8
+# define INT64_C(c) c ## L
+# elif SIZEOF_LONG_LONG >= 8
+# define INT64_C(c) c ## LL
+# endif
+#endif
+
+#ifndef HAVE_UINT64_T
+# ifdef HAVE_UINT64
+typedef uint64 uint64_t
+# elif HAVE_U_INT64_T
+typedef u_int64_t uint64_t;
+# elif SIZEOF_INT >= 8
+typedef unsigned int uint64_t;
+# elif SIZEOF_LONG >= 8
+typedef unsigned long uint64_t;
+# elif SIZEOF_LONG_LONG >= 8
+typedef unsigned long long uint64_t;
+# else
+# error "No suitable 64bit integer type found"
+# endif
+#endif
+
+#ifndef UINT64_C
+# if SIZEOF_INT >= 8
+# define UINT64_C(c) c ## U
+# elif SIZEOF_LONG >= 8
+# define UINT64_C(c) c ## UL
+# elif SIZEOF_LONG_LONG >= 8
+# define UINT64_C(c) c ## ULL
+# endif
+#endif
+
+#endif /* !PHP_WIN32 */
+#endif /* PHP_STDINT_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/main/php_streams.h b/main/php_streams.h
index 5acf942e43..c56014c62e 100644
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -131,31 +131,31 @@ typedef struct _php_stream_ops {
typedef struct _php_stream_wrapper_ops {
/* open/create a wrapped stream */
- php_stream *(*stream_opener)(php_stream_wrapper *wrapper, char *filename, char *mode,
+ 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 TSRMLS_DC);
/* close/destroy a wrapped stream */
int (*stream_closer)(php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC);
/* stat a wrapped stream */
int (*stream_stat)(php_stream_wrapper *wrapper, php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC);
/* stat a URL */
- int (*url_stat)(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
+ int (*url_stat)(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
/* open a "directory" stream */
- php_stream *(*dir_opener)(php_stream_wrapper *wrapper, char *filename, char *mode,
+ 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 TSRMLS_DC);
const char *label;
/* delete a file */
- int (*unlink)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
+ int (*unlink)(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
/* rename a file */
- int (*rename)(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC);
+ int (*rename)(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC);
/* Create/Remove directory */
- int (*stream_mkdir)(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
- int (*stream_rmdir)(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
+ int (*stream_mkdir)(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
+ int (*stream_rmdir)(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
/* Metadata handling */
- int (*stream_metadata)(php_stream_wrapper *wrapper, char *url, int options, void *value, php_stream_context *context TSRMLS_DC);
+ int (*stream_metadata)(php_stream_wrapper *wrapper, const char *url, int options, void *value, php_stream_context *context TSRMLS_DC);
} php_stream_wrapper_ops;
struct _php_stream_wrapper {
@@ -322,26 +322,26 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
#define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC)
#define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC)
-PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC);
+PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC);
/* CAREFUL! this is equivalent to puts NOT fputs! */
-PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC);
+PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC);
#define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf) TSRMLS_CC)
PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC);
#define php_stream_stat(stream, ssb) _php_stream_stat((stream), (ssb) TSRMLS_CC)
-PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
+PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
#define php_stream_stat_path(path, ssb) _php_stream_stat_path((path), 0, (ssb), NULL TSRMLS_CC)
#define php_stream_stat_path_ex(path, flags, ssb, context) _php_stream_stat_path((path), (flags), (ssb), (context) TSRMLS_CC)
-PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC);
+PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context TSRMLS_DC);
#define php_stream_mkdir(path, mode, options, context) _php_stream_mkdir(path, mode, options, context TSRMLS_CC)
-PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC);
+PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context TSRMLS_DC);
#define php_stream_rmdir(path, options, context) _php_stream_rmdir(path, options, context TSRMLS_CC)
-PHPAPI php_stream *_php_stream_opendir(char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC);
+PHPAPI php_stream *_php_stream_opendir(const char *path, int options, php_stream_context *context STREAMS_DC TSRMLS_DC);
#define php_stream_opendir(path, options, context) _php_stream_opendir((path), (options), (context) STREAMS_CC TSRMLS_CC)
PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_dirent *ent TSRMLS_DC);
#define php_stream_readdir(dirstream, dirent) _php_stream_readdir((dirstream), (dirent) TSRMLS_CC)
@@ -351,7 +351,7 @@ PHPAPI php_stream_dirent *_php_stream_readdir(php_stream *dirstream, php_stream_
PHPAPI int php_stream_dirent_alphasort(const char **a, const char **b);
PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b);
-PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context,
+PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags, php_stream_context *context,
int (*compare) (const char **a, const char **b) TSRMLS_DC);
#define php_stream_scandir(dirname, namelist, context, compare) _php_stream_scandir((dirname), (namelist), 0, (context), (compare) TSRMLS_CC)
@@ -540,13 +540,13 @@ void php_shutdown_stream_hashes(TSRMLS_D);
PHP_RSHUTDOWN_FUNCTION(streams);
BEGIN_EXTERN_C()
-PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
-PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC);
-PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
-PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC);
-PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
-PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC);
-PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC);
+PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
+PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC);
+PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
+PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC);
+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 TSRMLS_DC);
+PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC);
+PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC);
#define php_stream_open_wrapper(path, mode, options, opened) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC)
#define php_stream_open_wrapper_ex(path, mode, options, opened, context) _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC)
diff --git a/main/php_variables.c b/main/php_variables.c
index fd52f311d1..7018eae57b 100644
--- a/main/php_variables.c
+++ b/main/php_variables.c
@@ -55,7 +55,7 @@ PHPAPI void php_register_variable_safe(char *var, char *strval, int str_len, zva
PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars_array TSRMLS_DC)
{
char *p = NULL;
- char *ip; /* index pointer */
+ char *ip = NULL; /* index pointer */
char *index;
char *var, *var_orig;
int var_len, index_len;
diff --git a/main/rfc1867.c b/main/rfc1867.c
index ed7ce9c0c1..4adc25767d 100644
--- a/main/rfc1867.c
+++ b/main/rfc1867.c
@@ -34,6 +34,10 @@
#include "rfc1867.h"
#include "ext/standard/php_string.h"
+#if defined(PHP_WIN32) && !defined(HAVE_ATOLL)
+# define atoll(s) _atoi64(s)
+#endif
+
#define DEBUG_FILE_UPLOAD ZEND_DEBUG
static int dummy_encoding_translation(TSRMLS_D)
@@ -398,7 +402,7 @@ static int find_boundary(multipart_buffer *self, char *boundary TSRMLS_DC)
static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC)
{
char *line;
- mime_header_entry prev_entry, entry;
+ mime_header_entry prev_entry = {0}, entry;
int prev_len, cur_len;
/* didn't find boundary, abort */
@@ -676,8 +680,9 @@ 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;
- int boundary_len = 0, total_bytes = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
- int max_file_size = 0, skip_upload = 0, anonindex = 0, is_anonymous;
+ 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;
zval *http_post_files = NULL;
HashTable *uploaded_files = NULL;
multipart_buffer *mbuff;
@@ -898,7 +903,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
}
if (!strcasecmp(param, "MAX_FILE_SIZE")) {
- max_file_size = atol(value);
+ max_file_size = atoll(value);
}
efree(param);
@@ -1210,17 +1215,32 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
{
zval file_size, error_type;
+ int size_overflow = 0;
+ char file_size_buf[65];
- error_type.value.lval = cancel_upload;
- error_type.type = IS_LONG;
+ ZVAL_LONG(&error_type, cancel_upload);
/* Add $foo[error] */
if (cancel_upload) {
- file_size.value.lval = 0;
- file_size.type = IS_LONG;
+ ZVAL_LONG(&file_size, 0);
} else {
- file_size.value.lval = total_bytes;
- file_size.type = IS_LONG;
+ if (total_bytes > LONG_MAX) {
+#ifdef PHP_WIN32
+ if (_i64toa_s(total_bytes, file_size_buf, 65, 10)) {
+ file_size_buf[0] = '0';
+ file_size_buf[1] = '\0';
+ }
+#else
+ {
+ int __len = snprintf(file_size_buf, 65, "%lld", total_bytes);
+ file_size_buf[__len] = '\0';
+ }
+#endif
+ size_overflow = 1;
+
+ } else {
+ ZVAL_LONG(&file_size, total_bytes);
+ }
}
if (is_arr_upload) {
@@ -1237,7 +1257,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
snprintf(lbuf, llen, "%s_size", param);
}
if (!is_anonymous) {
- safe_php_register_variable_ex(lbuf, &file_size, NULL, 0 TSRMLS_CC);
+ if (size_overflow) {
+ ZVAL_STRING(&file_size, file_size_buf, 1);
+ }
+ safe_php_register_variable_ex(lbuf, &file_size, NULL, size_overflow TSRMLS_CC);
}
/* Add $foo[size] */
@@ -1246,7 +1269,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
} else {
snprintf(lbuf, llen, "%s[size]", param);
}
- register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, 0 TSRMLS_CC);
+ if (size_overflow) {
+ ZVAL_STRING(&file_size, file_size_buf, 1);
+ }
+ register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, size_overflow TSRMLS_CC);
}
efree(param);
}
diff --git a/main/snprintf.h b/main/snprintf.h
index de03542cad..f4ed4d234d 100644
--- a/main/snprintf.h
+++ b/main/snprintf.h
@@ -27,7 +27,7 @@ sprintf offers the ability to make a lot of failures since it does not know
the size of the buffer it uses. Therefore usage of sprintf often
results in possible entries for buffer overrun attacks. So please
use this version only if you are sure the call is safe. sprintf
- allways terminstes the buffer it writes to.
+ always terminstes the buffer it writes to.
snprintf knows the buffers size and will not write behind it. But you will
have to use either a static buffer or allocate a dynamic buffer
@@ -48,7 +48,7 @@ spprintf is the dynamical version of snprintf. It allocates the buffer in size
snprintf and offers possible memory leakes if you miss freeing the
buffer allocated by the function. Therfore this function should be
used where either no maximum is known or the maximum is much bigger
- than normal size required. spprintf allways terminates the buffer.
+ than normal size required. spprintf always terminates the buffer.
Example:
@@ -60,7 +60,7 @@ Example:
sprintf(buffer, "test"); | snprintf(buffer, MAX, "test"); | spprintf(&buffer, MAX, "text");
| | if (!buffer)
| | return OUT_OF_MEMORY
- // sprintf allways terminates | // manual termination of | // spprintf allays terminates buffer
+ // sprintf always terminates | // manual termination of | // spprintf allays terminates buffer
// buffer | // buffer *IS* required |
| buffer[MAX-1] = 0; |
action_with_buffer(buffer); | action_with_buffer(buffer); | action_with_buffer(buffer);
diff --git a/main/spprintf.h b/main/spprintf.h
index 397928a794..d9aa9533e5 100644
--- a/main/spprintf.h
+++ b/main/spprintf.h
@@ -22,7 +22,7 @@
The pbuf parameter of all spprintf version receives a pointer to the allocated
buffer. This buffer must be freed manually after usage using efree() function.
-The buffer will allways be terminated by a zero character. When pbuf is NULL
+The buffer will always be terminated by a zero character. When pbuf is NULL
the function can be used to calculate the required size of the buffer but for
that purpose snprintf is faster. When both pbuf and the return value are 0
than you are out of memory.
diff --git a/main/streams/cast.c b/main/streams/cast.c
index da6a293e45..bf96d3cf80 100644
--- a/main/streams/cast.c
+++ b/main/streams/cast.c
@@ -33,7 +33,7 @@
#if defined(HAVE_FUNOPEN) && !defined(HAVE_FOPENCOOKIE)
/* NetBSD 6.0+ uses off_t instead of fpos_t in funopen */
-# if defined(__NetBSD__) && (__NetBSD_Version__ > 600000000)
+# if defined(__NetBSD__) && (__NetBSD_Version__ >= 600000000)
# define PHP_FPOS_T off_t
# else
# define PHP_FPOS_T fpos_t
diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c
index 9c051a5921..8c3836fea0 100644
--- a/main/streams/glob_wrapper.c
+++ b/main/streams/glob_wrapper.c
@@ -109,9 +109,9 @@ PHPAPI int _php_glob_stream_get_count(php_stream *stream, int *pflags STREAMS_DC
}
/* }}} */
-static void php_glob_stream_path_split(glob_s_t *pglob, char *path, int get_path, char **p_file TSRMLS_DC) /* {{{ */
+static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int get_path, const char **p_file TSRMLS_DC) /* {{{ */
{
- char *pos, *gpath = path;
+ const char *pos, *gpath = path;
if ((pos = strrchr(path, '/')) != NULL) {
path = pos+1;
@@ -141,7 +141,7 @@ static size_t php_glob_stream_read(php_stream *stream, char *buf, size_t count T
{
glob_s_t *pglob = (glob_s_t *)stream->abstract;
php_stream_dirent *ent = (php_stream_dirent*)buf;
- char *path;
+ const char *path;
/* avoid problems if someone mis-uses the stream */
if (count == sizeof(php_stream_dirent) && pglob) {
@@ -206,12 +206,12 @@ php_stream_ops php_glob_stream_ops = {
};
/* {{{ php_glob_stream_opener */
-static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *path, char *mode,
+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 TSRMLS_DC)
{
glob_s_t *pglob;
int ret;
- char *tmp, *pos;
+ const char *tmp, *pos;
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
diff --git a/main/streams/memory.c b/main/streams/memory.c
index 328d3be399..90780ea78f 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -598,7 +598,9 @@ PHPAPI php_stream_ops php_stream_rfc2397_ops = {
php_stream_temp_set_option
};
-static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
+static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, const char *path,
+ const char *mode, int options, char **opened_path,
+ php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
{
php_stream *stream;
php_stream_temp_data *ts;
@@ -640,11 +642,11 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, cha
MAKE_STD_ZVAL(meta);
array_init(meta);
if (!semi) { /* there is only a mime type */
- add_assoc_stringl(meta, "mediatype", path, mlen, 1);
+ add_assoc_stringl(meta, "mediatype", (char *) path, mlen, 1);
mlen = 0;
} else if (sep && sep < semi) { /* there is a mime type */
plen = semi - path;
- add_assoc_stringl(meta, "mediatype", path, plen, 1);
+ add_assoc_stringl(meta, "mediatype", (char *) path, plen, 1);
mlen -= plen;
path += plen;
} else if (semi != path || mlen != sizeof(";base64")-1 || memcmp(path, ";base64", sizeof(";base64")-1)) { /* must be error since parameters are only allowed after mediatype */
diff --git a/main/streams/php_stream_plain_wrapper.h b/main/streams/php_stream_plain_wrapper.h
index d88b30c479..6700df0b29 100644
--- a/main/streams/php_stream_plain_wrapper.h
+++ b/main/streams/php_stream_plain_wrapper.h
@@ -30,7 +30,7 @@ BEGIN_EXTERN_C()
PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path, int options STREAMS_DC TSRMLS_DC);
#define php_stream_fopen(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened), 0 STREAMS_CC TSRMLS_CC)
-PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC);
+PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC);
#define php_stream_fopen_with_path(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened), 0 STREAMS_CC TSRMLS_CC)
PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC);
diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h
index c2d911032e..52df73d731 100644
--- a/main/streams/php_stream_transport.h
+++ b/main/streams/php_stream_transport.h
@@ -26,16 +26,16 @@
# include <sys/socket.h>
#endif
-typedef php_stream *(php_stream_transport_factory_func)(const char *proto, long protolen,
- char *resourcename, long resourcenamelen,
+typedef php_stream *(php_stream_transport_factory_func)(const char *proto, size_t protolen,
+ const char *resourcename, size_t resourcenamelen,
const char *persistent_id, int options, int flags,
struct timeval *timeout,
php_stream_context *context STREAMS_DC TSRMLS_DC);
typedef php_stream_transport_factory_func *php_stream_transport_factory;
BEGIN_EXTERN_C()
-PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC);
-PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC);
+PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC);
+PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC);
#define STREAM_XPORT_CLIENT 0
#define STREAM_XPORT_SERVER 1
@@ -46,7 +46,7 @@ PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC);
#define STREAM_XPORT_CONNECT_ASYNC 16
/* Open a client or server socket connection */
-PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options,
+PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options,
int flags, const char *persistent_id,
struct timeval *timeout,
php_stream_context *context,
@@ -59,13 +59,13 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
/* Bind the stream to a local address */
PHPAPI int php_stream_xport_bind(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
char **error_text
TSRMLS_DC);
/* Connect to a remote address */
PHPAPI int php_stream_xport_connect(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
int asynchronous,
struct timeval *timeout,
char **error_text,
@@ -141,7 +141,7 @@ typedef struct _php_stream_xport_param {
struct {
char *name;
- long namelen;
+ size_t namelen;
int backlog;
struct timeval *timeout;
struct sockaddr *addr;
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 39df31a170..949b827679 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -851,7 +851,7 @@ static php_stream_ops php_plain_files_dirstream_ops = {
NULL /* set_option */
};
-static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, char *path, char *mode,
+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 TSRMLS_DC)
{
DIR *dir = NULL;
@@ -989,7 +989,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, char *path, char *mode,
+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 TSRMLS_DC)
{
if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) {
@@ -999,7 +999,7 @@ static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, ch
return php_stream_fopen_rel(path, mode, opened_path, options);
}
-static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
char *p;
@@ -1029,7 +1029,7 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, in
return VCWD_STAT(url, &ssb->sb);
}
-static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
char *p;
int ret;
@@ -1058,7 +1058,7 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, int op
return 1;
}
-static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC)
{
char *p;
int ret;
@@ -1147,7 +1147,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
return 1;
}
-static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mode, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, int mode, int options, php_stream_context *context TSRMLS_DC)
{
int ret, recursive = options & PHP_STREAM_MKDIR_RECURSIVE;
char *p;
@@ -1235,7 +1235,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
}
}
-static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
#if PHP_WIN32
int url_len = strlen(url);
@@ -1262,7 +1262,7 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, char *url, int opt
return 1;
}
-static int php_plain_files_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
+static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
{
struct utimbuf *newtime;
char *p;
@@ -1371,10 +1371,11 @@ php_stream_wrapper php_plain_files_wrapper = {
};
/* {{{ php_stream_fopen_with_path */
-PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char *mode, const char *path, char **opened_path, int options STREAMS_DC TSRMLS_DC)
{
/* code ripped off from fopen_wrappers.c */
- char *pathbuf, *ptr, *end;
+ char *pathbuf, *end;
+ const char *ptr;
const char *exec_fname;
char trypath[MAXPATHLEN];
php_stream *stream;
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 623aabff60..d74f9fd04a 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -803,7 +803,7 @@ PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC)
return EOF;
}
-PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC)
+PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC)
{
int len;
char newline[2] = "\n"; /* is this OK for Win? */
@@ -835,11 +835,11 @@ PHPAPI int _php_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_D
return (stream->ops->stat)(stream, ssb TSRMLS_CC);
}
-PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len TSRMLS_DC)
+PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, size_t buf_len TSRMLS_DC)
{
size_t avail;
- char *cr, *lf, *eol = NULL;
- char *readptr;
+ const char *cr, *lf, *eol = NULL;
+ const char *readptr;
if (!buf) {
readptr = stream->readbuf + stream->readpos;
@@ -911,7 +911,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
if (avail > 0) {
size_t cpysz = 0;
char *readptr;
- char *eol;
+ const char *eol;
int done = 0;
readptr = stream->readbuf + stream->readpos;
@@ -994,11 +994,11 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
#define STREAM_BUFFERED_AMOUNT(stream) \
((size_t)(((stream)->writepos) - (stream)->readpos))
-static char *_php_stream_search_delim(php_stream *stream,
- size_t maxlen,
- size_t skiplen,
- char *delim, /* non-empty! */
- size_t delim_len TSRMLS_DC)
+static const char *_php_stream_search_delim(php_stream *stream,
+ size_t maxlen,
+ size_t skiplen,
+ const char *delim, /* non-empty! */
+ size_t delim_len TSRMLS_DC)
{
size_t seek_len;
@@ -1018,10 +1018,10 @@ static char *_php_stream_search_delim(php_stream *stream,
}
}
-PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char *delim, size_t delim_len TSRMLS_DC)
+PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC)
{
- char *ret_buf, /* returned buffer */
- *found_delim = NULL;
+ char *ret_buf; /* returned buffer */
+ const char *found_delim = NULL;
size_t buffered_len,
tent_ret_len; /* tentative returned length */
int has_delim = delim_len > 0;
@@ -1676,9 +1676,9 @@ int php_shutdown_stream_wrappers(int module_number TSRMLS_DC)
/* Validate protocol scheme names during registration
* Must conform to /^[a-zA-Z0-9+.-]+$/
*/
-static inline int php_stream_wrapper_scheme_validate(char *protocol, int protocol_len)
+static inline int php_stream_wrapper_scheme_validate(const char *protocol, unsigned int protocol_len)
{
- int i;
+ unsigned int i;
for(i = 0; i < protocol_len; i++) {
if (!isalnum((int)protocol[i]) &&
@@ -1693,9 +1693,9 @@ static inline int php_stream_wrapper_scheme_validate(char *protocol, int protoco
}
/* API for registering GLOBAL wrappers */
-PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
+PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
{
- int protocol_len = strlen(protocol);
+ unsigned int protocol_len = strlen(protocol);
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
return FAILURE;
@@ -1704,7 +1704,7 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w
return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}
-PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
+PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC)
{
return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1);
}
@@ -1719,9 +1719,9 @@ static void clone_wrapper_hash(TSRMLS_D)
}
/* API for registering VOLATILE wrappers */
-PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
+PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
{
- int protocol_len = strlen(protocol);
+ unsigned int protocol_len = strlen(protocol);
if (php_stream_wrapper_scheme_validate(protocol, protocol_len) == FAILURE) {
return FAILURE;
@@ -1734,7 +1734,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w
return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
}
-PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
+PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC)
{
if (!FG(stream_wrappers)) {
clone_wrapper_hash(TSRMLS_C);
@@ -1745,7 +1745,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
/* }}} */
/* {{{ php_stream_locate_url_wrapper */
-PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char **path_for_open, int options TSRMLS_DC)
+PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC)
{
HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
php_stream_wrapper **wrapperpp = NULL;
@@ -1880,7 +1880,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
/* {{{ _php_stream_mkdir
*/
-PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_mkdir(const char *path, int mode, int options, php_stream_context *context TSRMLS_DC)
{
php_stream_wrapper *wrapper = NULL;
@@ -1895,7 +1895,7 @@ PHPAPI int _php_stream_mkdir(char *path, int mode, int options, php_stream_conte
/* {{{ _php_stream_rmdir
*/
-PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_rmdir(const char *path, int options, php_stream_context *context TSRMLS_DC)
{
php_stream_wrapper *wrapper = NULL;
@@ -1909,10 +1909,10 @@ PHPAPI int _php_stream_rmdir(char *path, int options, php_stream_context *contex
/* }}} */
/* {{{ _php_stream_stat_path */
-PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
php_stream_wrapper *wrapper = NULL;
- char *path_to_open = path;
+ const char *path_to_open = path;
int ret;
/* Try to hit the cache first */
@@ -1954,12 +1954,12 @@ PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb,
/* }}} */
/* {{{ php_stream_opendir */
-PHPAPI php_stream *_php_stream_opendir(char *path, int options,
+PHPAPI php_stream *_php_stream_opendir(const char *path, int options,
php_stream_context *context STREAMS_DC TSRMLS_DC)
{
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
- char *path_to_open;
+ const char *path_to_open;
if (!path || !*path) {
return NULL;
@@ -2003,12 +2003,12 @@ 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(char *path, char *mode, int options,
+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 TSRMLS_DC)
{
php_stream *stream = NULL;
php_stream_wrapper *wrapper = NULL;
- char *path_to_open;
+ const char *path_to_open;
int persistent = options & STREAM_OPEN_PERSISTENT;
char *resolved_path = NULL;
char *copy_of_path = NULL;
@@ -2264,7 +2264,7 @@ PHPAPI int php_stream_dirent_alphasortr(const char **a, const char **b)
/* {{{ php_stream_scandir
*/
-PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context,
+PHPAPI int _php_stream_scandir(const char *dirname, char **namelist[], int flags, php_stream_context *context,
int (*compare) (const char **a, const char **b) TSRMLS_DC)
{
php_stream *stream;
@@ -2289,6 +2289,7 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_
} else {
if(vector_size*2 < vector_size) {
/* overflow */
+ php_stream_closedir(stream);
efree(vector);
return FAILURE;
}
@@ -2302,6 +2303,7 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_
nfiles++;
if(vector_size < 10 || nfiles == 0) {
/* overflow */
+ php_stream_closedir(stream);
efree(vector);
return FAILURE;
}
@@ -2310,7 +2312,7 @@ PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_
*namelist = vector;
- if (compare) {
+ if (nfiles > 0 && compare) {
qsort(*namelist, nfiles, sizeof(char *), (int(*)(const void *, const void *))compare);
}
return nfiles;
diff --git a/main/streams/transports.c b/main/streams/transports.c
index c24bf97ce6..2d31074ded 100644
--- a/main/streams/transports.c
+++ b/main/streams/transports.c
@@ -29,12 +29,12 @@ PHPAPI HashTable *php_stream_xport_get_hash(void)
return &xport_hash;
}
-PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC)
+PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC)
{
return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL);
}
-PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC)
+PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC)
{
return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1);
}
@@ -49,7 +49,7 @@ PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC)
if (local_err) { efree(local_err); local_err = NULL; } \
}
-PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int options,
+PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, int options,
int flags, const char *persistent_id,
struct timeval *timeout,
php_stream_context *context,
@@ -194,7 +194,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
/* Bind the stream to a local address */
PHPAPI int php_stream_xport_bind(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
char **error_text
TSRMLS_DC)
{
@@ -222,7 +222,7 @@ PHPAPI int php_stream_xport_bind(php_stream *stream,
/* Connect to a remote address */
PHPAPI int php_stream_xport_connect(php_stream *stream,
- const char *name, long namelen,
+ const char *name, size_t namelen,
int asynchronous,
struct timeval *timeout,
char **error_text,
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index 69edbaafa9..1e626e4b4c 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -45,14 +45,14 @@ struct php_user_stream_wrapper {
php_stream_wrapper wrapper;
};
-static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
-static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC);
-static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC);
-static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode,
+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 TSRMLS_DC);
+static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC);
+static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC);
+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 TSRMLS_DC);
static php_stream_wrapper_ops user_stream_wops = {
@@ -332,7 +332,8 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph
return object;
}
-static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filename, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
+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 TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
php_userstream_data_t *us;
@@ -437,7 +438,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena
return stream;
}
-static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, char *filename, char *mode,
+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 TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
@@ -1151,7 +1152,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
}
-static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zfuncname, *zretval;
@@ -1198,7 +1199,8 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio
return ret;
}
-static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char *url_to, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to,
+ int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zold_name, *znew_name, *zfuncname, *zretval;
@@ -1250,7 +1252,8 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char
return ret;
}
-static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode,
+ int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval;
@@ -1308,7 +1311,8 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, char *url, int mode,
return ret;
}
-static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url,
+ int options, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zoptions, *zfuncname, *zretval;
@@ -1361,7 +1365,8 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int option
return ret;
}
-static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option,
+ void *value, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zoption, *zvalue, *zfuncname, *zretval;
@@ -1444,7 +1449,8 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, char *url, int opt
}
-static int user_wrapper_stat_url(php_stream_wrapper *wrapper, char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
+static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags,
+ php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract;
zval *zfilename, *zfuncname, *zretval, *zflags;
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index a9c050f267..4edc68b015 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -230,7 +230,7 @@ static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC
#endif
}
-static inline int sock_sendto(php_netstream_data_t *sock, char *buf, size_t buflen, int flags,
+static inline int sock_sendto(php_netstream_data_t *sock, const char *buf, size_t buflen, int flags,
struct sockaddr *addr, socklen_t addrlen
TSRMLS_DC)
{
@@ -521,7 +521,7 @@ static inline int parse_unix_address(php_stream_xport_param *xparam, struct sock
}
#endif
-static inline char *parse_ip_address_ex(const char *str, int str_len, int *portno, int get_err, char **err TSRMLS_DC)
+static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *portno, int get_err, char **err TSRMLS_DC)
{
char *colon;
char *host = NULL;
@@ -774,8 +774,8 @@ static int php_tcp_sockop_set_option(php_stream *stream, int option, int value,
}
-PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, long protolen,
- char *resourcename, long resourcenamelen,
+PHPAPI php_stream *php_stream_generic_socket_factory(const char *proto, size_t protolen,
+ const char *resourcename, size_t resourcenamelen,
const char *persistent_id, int options, int flags,
struct timeval *timeout,
php_stream_context *context STREAMS_DC TSRMLS_DC)