Merge branch 'PHP-7.0' into PHP-7.1

This commit is contained in:
Nikita Popov 2017-04-09 13:14:45 +02:00
commit 84ef6fa80d
4 changed files with 24 additions and 2 deletions

2
NEWS
View file

@ -26,8 +26,10 @@ PHP NEWS
seconds). (Moritz Fain) seconds). (Moritz Fain)
- Standard: - Standard:
. Fixed bug #72071 (setcookie allows max-age to be negative). (Craig Duncan)
. Fixed bug #74361 (Compaction in array_rand() violates COW). (Nikita) . Fixed bug #74361 (Compaction in array_rand() violates COW). (Nikita)
13 Apr 2017, PHP 7.1.4 13 Apr 2017, PHP 7.1.4
- Core: - Core:

View file

@ -134,6 +134,8 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
if (expires > 0) { if (expires > 0) {
const char *p; const char *p;
char tsdelta[13]; char tsdelta[13];
double diff;
strlcat(cookie, COOKIE_EXPIRES, len + 100); strlcat(cookie, COOKIE_EXPIRES, len + 100);
dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, expires, 0); dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, expires, 0);
/* check to make sure that the year does not exceed 4 digits in length */ /* check to make sure that the year does not exceed 4 digits in length */
@ -148,7 +150,11 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
strlcat(cookie, ZSTR_VAL(dt), len + 100); strlcat(cookie, ZSTR_VAL(dt), len + 100);
zend_string_free(dt); zend_string_free(dt);
snprintf(tsdelta, sizeof(tsdelta), ZEND_LONG_FMT, (zend_long) difftime(expires, time(NULL))); diff = difftime(expires, time(NULL));
if (diff < 0) {
diff = 0;
}
snprintf(tsdelta, sizeof(tsdelta), ZEND_LONG_FMT, (zend_long) diff);
strlcat(cookie, COOKIE_MAX_AGE, len + 100); strlcat(cookie, COOKIE_MAX_AGE, len + 100);
strlcat(cookie, tsdelta, len + 100); strlcat(cookie, tsdelta, len + 100);
} }

View file

@ -0,0 +1,14 @@
--TEST--
Bug #72071 setcookie allows max-age to be negative
--INI--
date.timezone=UTC
--FILE--
<?php
$date = mktime(12, 25, 39, 4, 1, 2017);
setcookie("name", "value", $date);
?>
--EXPECT--
--EXPECTHEADERS--
Set-Cookie: name=value; expires=Sat, 01-Apr-2017 12:25:39 GMT; Max-Age=0

View file

@ -26,7 +26,7 @@ $expected = array(
'Set-Cookie: name=space+value', 'Set-Cookie: name=space+value',
'Set-Cookie: name=value', 'Set-Cookie: name=value',
'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsp).' GMT; Max-Age=5', 'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsp).' GMT; Max-Age=5',
'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsn).' GMT; Max-Age=-6', 'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsn).' GMT; Max-Age=0',
'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsc).' GMT; Max-Age=0', 'Set-Cookie: name=value; expires='.date('D, d-M-Y H:i:s', $tsc).' GMT; Max-Age=0',
'Set-Cookie: name=value; path=/path/', 'Set-Cookie: name=value; path=/path/',
'Set-Cookie: name=value; domain=domain.tld', 'Set-Cookie: name=value; domain=domain.tld',