diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-02-26 15:32:18 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-06-05 14:25:07 +0200 |
commit | a31f46421d7bf6f55dd9ac5876b8e2eacf7e0708 (patch) | |
tree | 24ffd7c5ae5e321c3994048fdd0fd9f68ae7457c /ext/session/session.c | |
parent | 528aa7932a839fc6319979c34aa372805d8dc41c (diff) | |
download | php-git-a31f46421d7bf6f55dd9ac5876b8e2eacf7e0708.tar.gz |
Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions
And convert some object to string conversion related recoverable
fatal errors into Error exceptions.
Improve exception safety of internal code performing string
conversions.
Diffstat (limited to 'ext/session/session.c')
-rw-r--r-- | ext/session/session.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index bf3ddee0d5..671968e8da 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1752,35 +1752,36 @@ static PHP_FUNCTION(session_set_cookie_params) lifetime = zval_get_string(lifetime_or_options); } + /* Exception during string conversion */ + if (EG(exception)) { + goto cleanup; + } + if (lifetime) { ini_name = zend_string_init("session.cookie_lifetime", sizeof("session.cookie_lifetime") - 1, 0); result = zend_alter_ini_entry(ini_name, lifetime, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - zend_string_release(lifetime); zend_string_release_ex(ini_name, 0); if (result == FAILURE) { - RETURN_FALSE; + RETVAL_FALSE; + goto cleanup; } } if (path) { ini_name = zend_string_init("session.cookie_path", sizeof("session.cookie_path") - 1, 0); result = zend_alter_ini_entry(ini_name, path, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - if (found > 0) { - zend_string_release(path); - } zend_string_release_ex(ini_name, 0); if (result == FAILURE) { - RETURN_FALSE; + RETVAL_FALSE; + goto cleanup; } } if (domain) { ini_name = zend_string_init("session.cookie_domain", sizeof("session.cookie_domain") - 1, 0); result = zend_alter_ini_entry(ini_name, domain, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - if (found > 0) { - zend_string_release(domain); - } zend_string_release_ex(ini_name, 0); if (result == FAILURE) { - RETURN_FALSE; + RETVAL_FALSE; + goto cleanup; } } if (!secure_null) { @@ -1788,7 +1789,8 @@ static PHP_FUNCTION(session_set_cookie_params) result = zend_alter_ini_entry_chars(ini_name, secure ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); zend_string_release_ex(ini_name, 0); if (result == FAILURE) { - RETURN_FALSE; + RETVAL_FALSE; + goto cleanup; } } if (!httponly_null) { @@ -1796,22 +1798,29 @@ static PHP_FUNCTION(session_set_cookie_params) result = zend_alter_ini_entry_chars(ini_name, httponly ? "1" : "0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); zend_string_release_ex(ini_name, 0); if (result == FAILURE) { - RETURN_FALSE; + RETVAL_FALSE; + goto cleanup; } } if (samesite) { ini_name = zend_string_init("session.cookie_samesite", sizeof("session.cookie_samesite") - 1, 0); result = zend_alter_ini_entry(ini_name, samesite, PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - if (found > 0) { - zend_string_release(samesite); - } zend_string_release_ex(ini_name, 0); if (result == FAILURE) { - RETURN_FALSE; + RETVAL_FALSE; + goto cleanup; } } - RETURN_TRUE; + RETVAL_TRUE; + +cleanup: + if (lifetime) zend_string_release(lifetime); + if (found > 0) { + if (path) zend_string_release(path); + if (domain) zend_string_release(domain); + if (samesite) zend_string_release(samesite); + } } /* }}} */ @@ -2364,7 +2373,10 @@ static PHP_FUNCTION(session_cache_expire) RETVAL_LONG(PS(cache_expire)); if (expires) { - convert_to_string_ex(expires); + if (!try_convert_to_string(expires)) { + return; + } + ini_name = zend_string_init("session.cache_expire", sizeof("session.cache_expire") - 1, 0); zend_alter_ini_entry(ini_name, Z_STR_P(expires), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); zend_string_release_ex(ini_name, 0); |