Merge branch 'master' into throw-error-in-extensions

This commit is contained in:
Aaron Piotrowski 2016-06-10 22:02:23 -05:00
commit e3c681aa5c
2658 changed files with 183307 additions and 184479 deletions

View file

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
| Copyright (c) 1997-2016 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 |
@ -16,7 +16,6 @@
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -172,7 +171,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
/* it is a directory only, see #40228 */
if (path_cleaned_len > 1 && IS_SLASH(path_cleaned[path_cleaned_len - 1])) {
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, path_cleaned);
is_dir_only = 1;
} else {
memcpy(file_dirname, path_cleaned, path_cleaned_len);
@ -315,12 +314,12 @@ static int php_zip_add_file(struct zip *za, const char *filename, size_t filenam
static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char **remove_path, size_t *remove_path_len, char **add_path, size_t *add_path_len) /* {{{ */
{
zval *option;
if ((option = zend_hash_str_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) {
*remove_all_path = zval_get_long(option);
}
/* If I add more options, it would make sense to create a nice static struct and loop over it. */
if ((option = zend_hash_str_find(HASH_OF(options), "remove_path", sizeof("remove_path") - 1)) != NULL) {
if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "remove_path", sizeof("remove_path") - 1)) != NULL) {
if (Z_TYPE_P(option) != IS_STRING) {
php_error_docref(NULL, E_WARNING, "remove_path option expected to be a string");
return -1;
@ -332,7 +331,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char
}
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %i, %i given)",
php_error_docref(NULL, E_WARNING, "remove_path string is too long (max: %d, %zd given)",
MAXPATHLEN - 1, Z_STRLEN_P(option));
return -1;
}
@ -340,7 +339,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char
*remove_path = Z_STRVAL_P(option);
}
if ((option = zend_hash_str_find(HASH_OF(options), "add_path", sizeof("add_path") - 1)) != NULL) {
if ((option = zend_hash_str_find(Z_ARRVAL_P(options), "add_path", sizeof("add_path") - 1)) != NULL) {
if (Z_TYPE_P(option) != IS_STRING) {
php_error_docref(NULL, E_WARNING, "add_path option expected to be a string");
return -1;
@ -352,7 +351,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char
}
if (Z_STRLEN_P(option) >= MAXPATHLEN) {
php_error_docref(NULL, E_WARNING, "add_path string too long (max: %i, %i given)",
php_error_docref(NULL, E_WARNING, "add_path string too long (max: %d, %zd given)",
MAXPATHLEN - 1, Z_STRLEN_P(option));
return -1;
}
@ -997,7 +996,7 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */
}
if (intern->za) {
if (zip_close(intern->za) != 0) {
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context");
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(intern->za));
return;
}
intern->za = NULL;
@ -1283,7 +1282,7 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_read)
}
if (zr_rsrc->zf) {
buffer = zend_string_alloc(len, 0);
buffer = zend_string_safe_alloc(1, len, 0, 0);
n = zip_fread(zr_rsrc->zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
if (n > 0) {
ZSTR_VAL(buffer)[n] = '\0';
@ -1496,6 +1495,7 @@ static ZIPARCHIVE_METHOD(close)
struct zip *intern;
zval *self = getThis();
ze_zip_object *ze_obj;
int err;
if (!self) {
RETURN_FALSE;
@ -1505,7 +1505,8 @@ static ZIPARCHIVE_METHOD(close)
ze_obj = Z_ZIP_P(self);
if (zip_close(intern)) {
if ((err = zip_close(intern))) {
php_error_docref(NULL, E_WARNING, "%s", zip_strerror(intern));
zip_discard(intern);
}
@ -1514,7 +1515,11 @@ static ZIPARCHIVE_METHOD(close)
ze_obj->filename_len = 0;
ze_obj->za = NULL;
RETURN_TRUE;
if (!err) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
@ -2293,13 +2298,13 @@ static ZIPARCHIVE_METHOD(setCompressionName)
ZIP_FROM_OBJECT(intern, this);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l",
&name, &name_len, &comp_method, &comp_flags) == FAILURE) {
return;
}
if (name_len < 1) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Empty string as entry name");
php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
}
idx = zip_name_locate(intern, name, 0);
@ -2330,7 +2335,7 @@ static ZIPARCHIVE_METHOD(setCompressionIndex)
ZIP_FROM_OBJECT(intern, this);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|l",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l",
&index, &comp_method, &comp_flags) == FAILURE) {
return;
}
@ -2663,7 +2668,7 @@ static ZIPARCHIVE_METHOD(extractTo)
for (i = 0; i < filecount; i++) {
char *file = (char*)zip_get_name(intern, i, ZIP_FL_UNCHANGED);
if (!php_zip_extract_file(intern, pathto, file, strlen(file))) {
if (!file || !php_zip_extract_file(intern, pathto, file, strlen(file))) {
RETURN_FALSE;
}
}
@ -2724,7 +2729,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
RETURN_FALSE;
}
buffer = zend_string_alloc(len, 0);
buffer = zend_string_safe_alloc(1, len, 0, 0);
n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
if (n < 1) {
zend_string_free(buffer);
@ -3034,6 +3039,37 @@ static PHP_MINIT_FUNCTION(zip)
REGISTER_ZIP_CLASS_CONST_LONG("FL_NODIR", ZIP_FL_NODIR);
REGISTER_ZIP_CLASS_CONST_LONG("FL_COMPRESSED", ZIP_FL_COMPRESSED);
REGISTER_ZIP_CLASS_CONST_LONG("FL_UNCHANGED", ZIP_FL_UNCHANGED);
#ifdef ZIP_FL_ENC_GUESS
/* Default filename encoding policy. */
REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_GUESS", ZIP_FL_ENC_GUESS);
#endif
#ifdef ZIP_FL_ENC_RAW
REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_RAW", ZIP_FL_ENC_RAW);
#endif
#ifdef ZIP_FL_ENC_STRICT
REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_STRICT", ZIP_FL_ENC_STRICT);
#endif
#ifdef ZIP_FL_ENC_UTF_8
REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_UTF_8", ZIP_FL_ENC_UTF_8);
#endif
#ifdef ZIP_FL_ENC_CP437
REGISTER_ZIP_CLASS_CONST_LONG("FL_ENC_CP437", ZIP_FL_ENC_CP437);
#endif
/* XXX The below are rather not implemented or to check whether makes sense to expose. */
/*#ifdef ZIP_FL_RECOMPRESS
REGISTER_ZIP_CLASS_CONST_LONG("FL_RECOMPRESS", ZIP_FL_RECOMPRESS);
#endif
#ifdef ZIP_FL_ENCRYPTED
REGISTER_ZIP_CLASS_CONST_LONG("FL_ENCRYPTED", ZIP_FL_ENCRYPTED);
#endif
#ifdef ZIP_FL_LOCAL
REGISTER_ZIP_CLASS_CONST_LONG("FL_LOCAL", ZIP_FL_LOCAL);
#endif
#ifdef ZIP_FL_CENTRAL
REGISTER_ZIP_CLASS_CONST_LONG("FL_CENTRAL", ZIP_FL_CENTRAL);
#endif */
REGISTER_ZIP_CLASS_CONST_LONG("CM_DEFAULT", ZIP_CM_DEFAULT);
REGISTER_ZIP_CLASS_CONST_LONG("CM_STORE", ZIP_CM_STORE);
REGISTER_ZIP_CLASS_CONST_LONG("CM_SHRINK", ZIP_CM_SHRINK);
@ -3129,7 +3165,6 @@ static PHP_MINFO_FUNCTION(zip)
php_info_print_table_start();
php_info_print_table_row(2, "Zip", "enabled");
php_info_print_table_row(2, "Extension Version","$Id$");
php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION);
php_info_print_table_row(2, "Libzip version", LIBZIP_VERSION);