Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

SetCookie With expiry of over 2038 fail on 32bit systems #5677

Closed
wants to merge 4 commits into from

4 participants

@mbn18

Title say it all. Bug 2038

@Maks3w

Change this to a negative comparison and call $this->markTestAsIncomplete('this test is skipped because ....');

Collaborator

Sorry. The correct method is markTestSkipped

@Maks3w

Looks that all this block can be merged with the previous if.

@mbn18

@Maks3w ok its up. Do you have merge rights?

@mbn18

@Maks3w , hi, can you authorize this?

@Maks3w
Collaborator

I have doubts between throw exception or your proposal of silent change. @weierophinney thoughts?

@Maks3w Maks3w added this to the 2.2.6 milestone
@weierophinney

I'm fine with the proposed silent change. Developers will expect this to "just do the right thing".

@ralphschindler ralphschindler self-assigned this
@weierophinney weierophinney self-assigned this
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/5677' into develop
Forward port #5677
e5ab5fe
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-http
@weierophinney weierophinney Merge pull request zendframework/zf2#5677 from mbn18/master
SetCookie With expiry of over 2038 fail on 32bit systems
860f756
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-http
@weierophinney weierophinney Merge branch 'hotfix/5677' fba45eb
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-http
@weierophinney weierophinney Merge branch 'hotfix/5677' into develop e62d9d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
15 library/Zend/Http/Header/SetCookie.php
@@ -358,15 +358,24 @@ public function setExpires($expires)
return $this;
}
+ $tsExpires = $expires;
if (is_string($expires)) {
- $expires = strtotime($expires);
+ $tsExpires = strtotime($expires);
+
+ // if $tsExpires is invalid and PHP is compiled as 32bit. Check if it fail reason is the 2038 bug
+ if (!is_int($tsExpires) && PHP_INT_SIZE === 4) {
+ $dateTime = new \DateTime($expires);
+ if ( $dateTime->format('Y') > 2038) {
+ $tsExpires = PHP_INT_MAX;
+ }
+ }
}
- if (!is_int($expires) || $expires < 0) {
+ if (!is_int($tsExpires) || $tsExpires < 0) {
throw new Exception\InvalidArgumentException('Invalid expires time specified');
}
- $this->expires = $expires;
+ $this->expires = $tsExpires;
return $this;
}
View
13 tests/ZendTest/Http/Header/SetCookieTest.php
@@ -254,6 +254,19 @@ public function testSetCookieSetExpiresWithUnixEpochString()
$this->assertSame($target, $setCookieHeader->getFieldValue());
}
+ /**
+ * Check that setCookie does not fail when an expiry date which is bigger then 2038 is supplied (effect only 32bit systems)
+ */
+ public function testSetCookieSetExpiresWithStringDateBiggerThen2038()
+ {
+ if ( PHP_INT_SIZE !== 4 ) {
+ $this->markTestSkipped('Testing set cookie expiry which is over 2038 is only relevant on 32bit systems');
+ return;
+ }
+ $setCookieHeader = new SetCookie('myname', 'myvalue', 'Thu, 01-Jan-2040 00:00:00 GMT');
+ $this->assertSame(2147483647, $setCookieHeader->getExpires(true));
+ }
+
public function testIsValidForRequestSubdomainMatch()
{
$setCookieHeader = new SetCookie(
Something went wrong with that request. Please try again.