diff options
author | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-06-05 14:40:40 +0200 |
---|---|---|
committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-06-06 09:23:34 +0200 |
commit | aa9b0ccda88531f9bb3f2149db002c5fcaaa7b14 (patch) | |
tree | 280b5f373ee382cad61fc0c0abc575bcb6c8f544 /ext/session/session.c | |
parent | 170d63ec62ff61de0b4394099d2e14732d0392fb (diff) | |
download | php-git-aa9b0ccda88531f9bb3f2149db002c5fcaaa7b14.tar.gz |
Add tests to check mismatching function signatures
Closes GH-5666
Diffstat (limited to 'ext/session/session.c')
-rw-r--r-- | ext/session/session.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/ext/session/session.c b/ext/session/session.c index 220bfe3638..993f6a063f 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1917,24 +1917,28 @@ PHP_FUNCTION(session_module_name) } /* }}} */ -/* {{{ proto bool session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid) - Sets user-level functions */ -PHP_FUNCTION(session_set_save_handler) -{ - zval *args = NULL; - int i, num_args, argc = ZEND_NUM_ARGS(); - zend_string *ini_name, *ini_val; - +static int save_handler_check_session() { if (PS(session_status) == php_session_active) { php_error_docref(NULL, E_WARNING, "Cannot change save handler when session is active"); - RETURN_FALSE; + return FAILURE; } if (SG(headers_sent)) { php_error_docref(NULL, E_WARNING, "Cannot change save handler when headers already sent"); - RETURN_FALSE; + return FAILURE; } + return SUCCESS; +} + +/* {{{ proto bool session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid) + Sets user-level functions */ +PHP_FUNCTION(session_set_save_handler) +{ + zval *args = NULL; + int i, num_args, argc = ZEND_NUM_ARGS(); + zend_string *ini_name, *ini_val; + if (argc > 0 && argc <= 2) { zval *obj = NULL; zend_string *func_name; @@ -1945,6 +1949,10 @@ PHP_FUNCTION(session_set_save_handler) RETURN_THROWS(); } + if (save_handler_check_session() == FAILURE) { + RETURN_FALSE; + } + /* For compatibility reason, implemented interface is not checked */ /* Find implemented methods - SessionHandlerInterface */ i = 0; @@ -2047,6 +2055,10 @@ PHP_FUNCTION(session_set_save_handler) RETURN_THROWS(); } + if (save_handler_check_session() == FAILURE) { + RETURN_FALSE; + } + /* remove shutdown function */ remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") - 1); |