Skip to content

Commit a6a5d46

Browse files
committed
Simplify and move check for too high expiry time, which you can't reach on 32bit systems
1 parent 15e3fcb commit a6a5d46

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ext/standard/head.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e
110110
get_active_function_name());
111111
return FAILURE;
112112
}
113+
#ifdef ZEND_ENABLE_ZVAL_LONG64
114+
if (expires >= 253402300800) {
115+
zend_value_error("%s(): \"expires\" option cannot have a year greater than 9999",
116+
get_active_function_name());
117+
return FAILURE;
118+
}
119+
#endif
120+
113121
/* Should check value of SameSite? */
114122

115123
if (value == NULL || ZSTR_LEN(value) == 0) {
@@ -136,19 +144,12 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e
136144
} else {
137145
smart_str_append(&buf, value);
138146
}
147+
139148
if (expires > 0) {
140149
double diff;
141150

142151
smart_str_appends(&buf, COOKIE_EXPIRES);
143152
dt = php_format_date("D, d M Y H:i:s \\G\\M\\T", sizeof("D, d M Y H:i:s \\G\\M\\T")-1, expires, 0);
144-
/* check to make sure that the year does not exceed 4 digits in length */
145-
if (php_idate('Y', expires, 0) > 9999) {
146-
zend_string_free(dt);
147-
smart_str_free(&buf);
148-
zend_value_error("%s(): \"expires\" option cannot have a year greater than 9999",
149-
get_active_function_name());
150-
return FAILURE;
151-
}
152153

153154
smart_str_append(&buf, dt);
154155
zend_string_free(dt);

0 commit comments

Comments
 (0)