-
Notifications
You must be signed in to change notification settings - Fork 8k
ext/session: fix cookie_lifetime overflow #21704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -706,11 +706,25 @@ static PHP_INI_MH(OnUpdateCookieLifetime) | |
| #else | ||
| const zend_long maxcookie = ZEND_LONG_MAX / 2 - 1; | ||
| #endif | ||
| zend_long v = (zend_long)atol(ZSTR_VAL(new_value)); | ||
| if (v < 0) { | ||
| zend_long lval = 0; | ||
| int oflow = 0; | ||
| uint8_t type = is_numeric_string_ex(ZSTR_VAL(new_value), ZSTR_LEN(new_value), &lval, NULL, false, &oflow, NULL); | ||
| if (type == 0) { | ||
| php_error_docref(NULL, E_WARNING, "Invalid value for CookieLifetime"); | ||
| return FAILURE; | ||
| } else if (type == IS_DOUBLE && oflow == 0) { | ||
| php_error_docref(NULL, E_WARNING, "CookieLifetime must be an integer"); | ||
| return FAILURE; | ||
| } | ||
| zend_long v = lval; | ||
| if (oflow < 0 || v < 0) { | ||
| php_error_docref(NULL, E_WARNING, "CookieLifetime cannot be negative"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this error could be updated to the more standard wording of |
||
| return FAILURE; | ||
| } else if (v > maxcookie) { | ||
| } else if (oflow > 0 || v > maxcookie) { | ||
| php_error_docref(NULL, E_WARNING, "CookieLifetime value too large, value was set to the maximum of " ZEND_LONG_FMT, maxcookie); | ||
| zend_long *p = ZEND_INI_GET_ADDR(); | ||
| *p = maxcookie; | ||
| entry->value = zend_long_to_str(maxcookie); | ||
| return SUCCESS; | ||
|
Comment on lines
+723
to
728
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this use to actually update the INI setting or was it just returning SUCCESS even if it was failing? :| |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --TEST-- | ||
| session.cookie_lifetime rejects non-integer values | ||
| --EXTENSIONS-- | ||
| session | ||
| --SKIPIF-- | ||
| <?php include('skipif.inc'); ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| ob_start(); | ||
|
|
||
| ini_set("session.cookie_lifetime", 100); | ||
|
|
||
| // Float strings are rejected | ||
| ini_set("session.cookie_lifetime", "1.5"); | ||
| var_dump(ini_get("session.cookie_lifetime")); | ||
|
|
||
| // Non-numeric strings are rejected | ||
| ini_set("session.cookie_lifetime", "abc"); | ||
| var_dump(ini_get("session.cookie_lifetime")); | ||
|
|
||
| // Negative values are rejected | ||
| ini_set("session.cookie_lifetime", -1); | ||
| var_dump(ini_get("session.cookie_lifetime")); | ||
|
|
||
| // Negative overflow strings are rejected | ||
| ini_set("session.cookie_lifetime", "-99999999999999999999"); | ||
| var_dump(ini_get("session.cookie_lifetime")); | ||
|
|
||
| ob_end_flush(); | ||
| ?> | ||
| --EXPECTF-- | ||
| Warning: ini_set(): CookieLifetime must be an integer in %s on line %d | ||
| string(3) "100" | ||
|
|
||
| Warning: ini_set(): Invalid value for CookieLifetime in %s on line %d | ||
| string(3) "100" | ||
|
|
||
| Warning: ini_set(): CookieLifetime cannot be negative in %s on line %d | ||
| string(3) "100" | ||
|
|
||
| Warning: ini_set(): CookieLifetime cannot be negative in %s on line %d | ||
| string(3) "100" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --TEST-- | ||
| session.cookie_lifetime overflow value is clamped | ||
| --EXTENSIONS-- | ||
| session | ||
| --SKIPIF-- | ||
| <?php include('skipif.inc'); ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| ob_start(); | ||
|
|
||
| // Set a valid value first | ||
| ini_set("session.cookie_lifetime", 100); | ||
| var_dump(ini_get("session.cookie_lifetime")); | ||
|
|
||
| // Set an overflow value - should succeed with warning, value clamped | ||
| ini_set("session.cookie_lifetime", PHP_INT_MAX); | ||
| $val = (int) ini_get("session.cookie_lifetime"); | ||
| var_dump($val < PHP_INT_MAX); // clamped, not PHP_INT_MAX | ||
| var_dump($val > 0); | ||
|
|
||
| // Valid values still work after clamping | ||
| ini_set("session.cookie_lifetime", 200); | ||
| var_dump(ini_get("session.cookie_lifetime")); | ||
|
|
||
| ob_end_flush(); | ||
| ?> | ||
| --EXPECTF-- | ||
| string(3) "100" | ||
|
|
||
| Warning: ini_set(): CookieLifetime value too large, value was set to the maximum of %d in %s on line %d | ||
| bool(true) | ||
| bool(true) | ||
| string(3) "200" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this into an
if (UNEXPECTED(type != IS_LONG)) {}block?