Skip to content

Commit 320237f

Browse files
committed
Merge branch 'master' into sccp
* master: Fixed memory leak introduced by 7cb5bdf eliminate casts remove checks for eol dependencies improve test Small fix in ext/ldap, Moved vars definitions to the beginning of the block using them ZipArchive implements countable, added ZipArchive::count() method
2 parents 63bbed5 + 7be2637 commit 320237f

File tree

11 files changed

+87
-48
lines changed

11 files changed

+87
-48
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ PHP NEWS
4949
. Fixed bug #74883 (SQLite3::__construct() produces "out of memory" exception
5050
with invalid flags). (Anatol)
5151

52+
- ZIP:
53+
. ZipArchive implements countable, added ZipArchive::count() method. (Remi)
54+
5255
06 Jul 2017, PHP 7.2.0alpha3
5356

5457
- Core:

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ PHP 7.2 UPGRADE NOTES
143143
ZipArchive::EM_AES_192
144144
ZipArchive::EM_AES_256
145145
. accept 'password' from zip stream context
146+
. ZipArchive implements countable, added ZipArchive::count() method.
147+
146148

147149
========================================
148150
3. Changes in SAPI modules

ext/ldap/ldap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,8 +2199,6 @@ PHP_FUNCTION(ldap_sort)
21992199
PHP_FUNCTION(ldap_get_option)
22002200
{
22012201
zval *link, *retval;
2202-
zval tmp1;
2203-
int num_entries;
22042202
ldap_linkdata *ld;
22052203
zend_long option;
22062204

@@ -2348,6 +2346,8 @@ PHP_FUNCTION(ldap_get_option)
23482346
case LDAP_OPT_SERVER_CONTROLS:
23492347
case LDAP_OPT_CLIENT_CONTROLS:
23502348
{
2349+
zval tmp1;
2350+
int num_entries;
23512351
LDAPControl **ctrls = NULL, **ctrlp;
23522352

23532353
if (ldap_get_option(ld->link, option, &ctrls) || ctrls == NULL) {

ext/pdo_dblib/config.w32

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,21 @@ if (PHP_PDO_DBLIB != "no") {
2222
ARG_WITH("pdo-mssql", "Native MS-SQL support for PDO", "no");
2323

2424
if (PHP_PDO_MSSQL != "no") {
25-
/* if they pointed us to a freetds dir, pick that up,
26-
* otherwise we'll poke around and look for MSSQL libs */
27-
28-
pdo_mssql_locations = new Array(
29-
PHP_PDO_MSSQL,
30-
"\\Program Files\\Microsoft SQL Server\\80",
31-
"\\MSSQL8",
32-
"\\MSSQL7",
33-
PHP_PHP_BUILD + "\\MSSQL80"
34-
);
3525
PDO_DBLIB_FLAVOUR = 0;
3626

3727
if (CHECK_LIB("sybdb.lib", "pdo_mssql", PHP_PDO_MSSQL) &&
3828
CHECK_HEADER_ADD_INCLUDE("sybfront.h", "CFLAGS_PDO_MSSQL",
3929
PHP_PDO_MSSQL, null, null, true)) {
4030
/* smells like FreeTDS (or maybe native sybase dblib) */
4131
PDO_DBLIB_FLAVOUR = "freetds";
42-
} else {
43-
44-
for (i = 0; i < pdo_mssql_locations.length; i++) {
45-
if (CHECK_LIB("ntwdblib.lib", "pdo_mssql",
46-
pdo_mssql_locations[i] + "\\DevTools\\Lib") &&
47-
CHECK_HEADER_ADD_INCLUDE("sqlfront.h", "CFLAGS_PDO_MSSQL",
48-
pdo_mssql_locations[i] + "\\DevTools\\Include",
49-
null, null, true)) {
50-
if (pdo_mssql_locations[i] == 'yes') {
51-
PDO_DBLIB_FLAVOUR = 70;
52-
} else {
53-
pdo_mssql_locations[i].match(new RegExp("(\\d)"));
54-
PDO_DBLIB_FLAVOUR = RegExp.$1 + 0;
55-
}
56-
break;
57-
}
58-
}
5932
}
6033

6134
if (PDO_DBLIB_FLAVOUR != 0) {
6235
EXTENSION("pdo_mssql", "pdo_dblib.c dblib_driver.c dblib_stmt.c", null, null, null, "ext\\pdo_mssql");
63-
if (PDO_DBLIB_FLAVOUR != "freetds") {
64-
ADD_FLAG("CFLAGS_PDO_MSSQL", "/DPHP_DBLIB_IS_MSSQL=1 /DDBNTWIN32=1 /DMSSQL" + PDO_DBLIB_FLAVOUR + "0=1 /DMSSQL_VERSION=\\\"" + PDO_DBLIB_FLAVOUR + ".0\\\"");
65-
ADD_FLAG("CFLAGS_PDO_MSSQL", "/DPDO_DBLIB_IS_MSSQL=" + PDO_DBLIB_FLAVOUR);
66-
PDO_DBLIB_FLAVOUR = "MSSQL_" + PDO_DBLIB_FLAVOUR;
67-
}
6836
ADD_FLAG('CFLAGS_PDO_MSSQL', "/D PDO_DBLIB_FLAVOUR=\\\"" + PDO_DBLIB_FLAVOUR + "\\\"");
6937
ADD_EXTENSION_DEP('pdo_mssql', 'pdo');
7038
} else {
7139
WARNING("pdo_mssql not enabled, libraries or headers not found")
7240
}
7341
}
42+

ext/standard/tests/general_functions/proc_open-win32-mb0.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ $p = proc_open(
2929
array("bypass_shell" => true)
3030
);
3131

32-
echo fread($pipes[1], 1024);
32+
$out = "";
33+
34+
while (!feof($pipes[1])) {
35+
$out .= fread($pipes[1], 1024);
36+
}
3337

3438
proc_close($p);
3539

40+
echo $out;
41+
3642
?>
3743
==DONE==
3844
--EXPECTF--

ext/standard/tests/general_functions/proc_open-win32-mb1.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ $p = proc_open(
2626
$pipes
2727
);
2828

29-
echo fread($pipes[1], 1024);
29+
$out = "";
30+
31+
while (!feof($pipes[1])) {
32+
$out .= fread($pipes[1], 1024);
33+
}
3034

3135
proc_close($p);
3236

37+
echo $out;
38+
3339
?>
3440
==DONE==
3541
--EXPECTF--

ext/standard/var_unserializer.re

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static zend_always_inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTab
391391
ZVAL_UNDEF(&key);
392392

393393
if (!php_var_unserialize_internal(&key, p, max, NULL)) {
394-
zval_dtor(&key);
394+
zval_ptr_dtor(&key);
395395
return 0;
396396
}
397397

@@ -421,7 +421,7 @@ numeric_key:
421421
data = zend_hash_add_new(ht, Z_STR(key), &d);
422422
}
423423
} else {
424-
zval_dtor(&key);
424+
zval_ptr_dtor(&key);
425425
return 0;
426426
}
427427
} else {
@@ -435,7 +435,7 @@ string_key:
435435
size_t unmangled_prop_len;
436436

437437
if (UNEXPECTED(zend_unmangle_property_name_ex(Z_STR(key), &unmangled_class, &unmangled_prop, &unmangled_prop_len) == FAILURE)) {
438-
zval_dtor(&key);
438+
zval_ptr_dtor(&key);
439439
return 0;
440440
}
441441

@@ -465,7 +465,7 @@ string_key:
465465
new_key = unmangled;
466466
}
467467
zend_string_release(Z_STR(key));
468-
Z_STR(key) = new_key;
468+
ZVAL_STR(&key, new_key);
469469
} else {
470470
zend_string_release(unmangled);
471471
}
@@ -485,13 +485,13 @@ string_key:
485485
convert_to_string(&key);
486486
goto string_key;
487487
} else {
488-
zval_dtor(&key);
488+
zval_ptr_dtor(&key);
489489
return 0;
490490
}
491491
}
492492

493493
if (!php_var_unserialize_internal(data, p, max, var_hash)) {
494-
zval_dtor(&key);
494+
zval_ptr_dtor(&key);
495495
return 0;
496496
}
497497

@@ -505,7 +505,7 @@ string_key:
505505
var_push_dtor(var_hash, data);
506506
}
507507

508-
zval_dtor(&key);
508+
zval_ptr_dtor(&key);
509509

510510
if (elements && *(*p-1) != ';' && *(*p-1) != '}') {
511511
(*p)--;

ext/zip/php_zip.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include "ext/standard/php_string.h"
2929
#include "ext/pcre/php_pcre.h"
3030
#include "ext/standard/php_filestat.h"
31+
#if PHP_VERSION_ID >= 70200
32+
#include "zend_interfaces.h"
33+
#elif defined(HAVE_SPL)
34+
#include "ext/spl/spl_iterators.h"
35+
#endif
3136
#include "php_zip.h"
3237

3338
/* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
@@ -1548,6 +1553,23 @@ static ZIPARCHIVE_METHOD(close)
15481553
}
15491554
/* }}} */
15501555

1556+
/* {{{ proto bool ZipArchive::count()
1557+
close the zip archive */
1558+
static ZIPARCHIVE_METHOD(count)
1559+
{
1560+
struct zip *intern;
1561+
zval *self = getThis();
1562+
1563+
if (!self) {
1564+
RETURN_FALSE;
1565+
}
1566+
1567+
ZIP_FROM_OBJECT(intern, self);
1568+
1569+
RETVAL_LONG(zip_get_num_files(intern));
1570+
}
1571+
/* }}} */
1572+
15511573
/* {{{ proto string ZipArchive::getStatusString()
15521574
* Returns the status error message, system and/or zip messages */
15531575
static ZIPARCHIVE_METHOD(getStatusString)
@@ -3069,6 +3091,7 @@ static const zend_function_entry zip_class_functions[] = {
30693091
ZIPARCHIVE_ME(open, arginfo_ziparchive_open, ZEND_ACC_PUBLIC)
30703092
ZIPARCHIVE_ME(setPassword, arginfo_ziparchive_setpassword, ZEND_ACC_PUBLIC)
30713093
ZIPARCHIVE_ME(close, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
3094+
ZIPARCHIVE_ME(count, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
30723095
ZIPARCHIVE_ME(getStatusString, arginfo_ziparchive__void, ZEND_ACC_PUBLIC)
30733096
ZIPARCHIVE_ME(addEmptyDir, arginfo_ziparchive_addemptydir, ZEND_ACC_PUBLIC)
30743097
ZIPARCHIVE_ME(addFromString, arginfo_ziparchive_addfromstring, ZEND_ACC_PUBLIC)
@@ -3141,6 +3164,11 @@ static PHP_MINIT_FUNCTION(zip)
31413164
php_zip_register_prop_handler(&zip_prop_handlers, "numFiles", php_zip_get_num_files, NULL, NULL, IS_LONG);
31423165
php_zip_register_prop_handler(&zip_prop_handlers, "filename", NULL, NULL, php_zipobj_get_filename, IS_STRING);
31433166
php_zip_register_prop_handler(&zip_prop_handlers, "comment", NULL, php_zipobj_get_zip_comment, NULL, IS_STRING);
3167+
#if PHP_VERSION_ID >= 70200
3168+
zend_class_implements(zip_class_entry, 1, zend_ce_countable);
3169+
#elif defined(HAVE_SPL)
3170+
zend_class_implements(zip_class_entry, 1, spl_ce_Countable);
3171+
#endif
31443172

31453173
REGISTER_ZIP_CLASS_CONST_LONG("CREATE", ZIP_CREATE);
31463174
REGISTER_ZIP_CLASS_CONST_LONG("EXCL", ZIP_EXCL);

ext/zip/php_zip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern zend_module_entry zip_module_entry;
3737
#define ZIP_OVERWRITE ZIP_TRUNCATE
3838
#endif
3939

40-
#define PHP_ZIP_VERSION "1.14.0"
40+
#define PHP_ZIP_VERSION "1.15.0"
4141

4242
#define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
4343

ext/zip/tests/oo_count.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
ziparchive::count()
3+
--SKIPIF--
4+
<?php
5+
/* $Id$ */
6+
if(!extension_loaded('zip')) die('skip');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$dirname = dirname(__FILE__) . '/';
12+
$file = $dirname . 'test.zip';
13+
14+
$zip = new ZipArchive;
15+
if (!$zip->open($file)) {
16+
exit('failed');
17+
}
18+
19+
var_dump($zip->numFiles, count($zip), $zip->numFiles == count($zip));
20+
?>
21+
Done
22+
--EXPECTF--
23+
int(4)
24+
int(4)
25+
bool(true)
26+
Done

main/streams/plain_wrapper.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
12291229
/* we look for directory separator from the end of string, thus hopefuly reducing our work load */
12301230
char *e;
12311231
zend_stat_t sb;
1232-
int dir_len = (int)strlen(dir);
1233-
int offset = 0;
1232+
size_t dir_len = strlen(dir), offset = 0;
12341233
char buf[MAXPATHLEN];
12351234

12361235
if (!expand_filepath_with_mode(dir, buf, NULL, 0, CWD_EXPAND )) {
@@ -1438,7 +1437,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char
14381437
const char *ptr;
14391438
char trypath[MAXPATHLEN];
14401439
php_stream *stream;
1441-
int filename_length;
1440+
size_t filename_length;
14421441
zend_string *exec_filename;
14431442

14441443
if (opened_path) {
@@ -1449,7 +1448,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char
14491448
return NULL;
14501449
}
14511450

1452-
filename_length = (int)strlen(filename);
1451+
filename_length = strlen(filename);
14531452
#ifndef PHP_WIN32
14541453
(void) filename_length;
14551454
#endif

0 commit comments

Comments
 (0)