summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-04-09 13:15:04 +0200
committerNikita Popov <nikita.ppv@gmail.com>2017-04-09 13:15:04 +0200
commit430eea84b84a8c9d733a38cafaa32d494cadf13b (patch)
treeba373cfac48f4fb06e8a1ab91e2fc18063d15e3b
parent4ee6b52d0f4483c6e063b2dd3bb7af1c8a94300d (diff)
parent84ef6fa80dbfc1ff8942209b13d9fb5439409729 (diff)
downloadphp-git-430eea84b84a8c9d733a38cafaa32d494cadf13b.tar.gz
Merge branch 'PHP-7.1'
-rw-r--r--ext/standard/head.c8
-rw-r--r--ext/standard/tests/network/bug72071.phpt14
-rw-r--r--ext/standard/tests/network/setcookie.phpt2
3 files changed, 22 insertions, 2 deletions
diff --git a/ext/standard/head.c b/ext/standard/head.c
index 52cdb34534..b8632c70ed 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -138,6 +138,8 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
if (expires > 0) {
const char *p;
char tsdelta[13];
+ double diff;
+
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);
/* check to make sure that the year does not exceed 4 digits in length */
@@ -152,7 +154,11 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires,
strlcat(cookie, ZSTR_VAL(dt), len + 100);
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, tsdelta, len + 100);
}
diff --git a/ext/standard/tests/network/bug72071.phpt b/ext/standard/tests/network/bug72071.phpt
new file mode 100644
index 0000000000..6d19ab46e3
--- /dev/null
+++ b/ext/standard/tests/network/bug72071.phpt
@@ -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
diff --git a/ext/standard/tests/network/setcookie.phpt b/ext/standard/tests/network/setcookie.phpt
index 68c929997d..3582d341a7 100644
--- a/ext/standard/tests/network/setcookie.phpt
+++ b/ext/standard/tests/network/setcookie.phpt
@@ -26,7 +26,7 @@ $expected = array(
'Set-Cookie: name=space+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', $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; path=/path/',
'Set-Cookie: name=value; domain=domain.tld',