Skip to content

check if session was allocated on PS_OPEN_FUNC #198

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

Merged
merged 1 commit into from
Nov 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
check if session was allocated on PS_OPEN_FUNC
  • Loading branch information
samm-git committed Nov 12, 2015
commit 23db27a09ba3b35756305aa5bf487a9e530e9166
20 changes: 20 additions & 0 deletions php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ PS_OPEN_FUNC(memcached)
PS_CLOSE_FUNC(memcached)
{
memcached_sess *memc_sess = PS_GET_MOD_DATA();

if (!memc_sess) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
return FAILURE;
}

if (MEMC_G(sess_locking_enabled)) {
php_memc_sess_unlock(memc_sess->memc_sess);
Expand Down Expand Up @@ -307,6 +312,11 @@ PS_READ_FUNC(memcached)
memcached_sess *memc_sess = PS_GET_MOD_DATA();
size_t key_length;

if (!memc_sess) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
return FAILURE;
}

key_length = strlen(MEMC_G(sess_prefix)) + key_len + 5; // prefix + "lock."
if (!key_length || key_length >= MEMCACHED_MAX_KEY) {
php_error_docref(NULL, E_WARNING, "The session id is too long or contains illegal characters");
Expand Down Expand Up @@ -339,6 +349,11 @@ PS_WRITE_FUNC(memcached)
memcached_return status;
memcached_sess *memc_sess = PS_GET_MOD_DATA();
size_t key_length;

if (!memc_sess) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
return FAILURE;
}

key_length = strlen(MEMC_G(sess_prefix)) + key_len + 5; // prefix + "lock."
if (!key_length || key_length >= MEMCACHED_MAX_KEY) {
Expand Down Expand Up @@ -371,6 +386,11 @@ PS_DESTROY_FUNC(memcached)
{
memcached_sess *memc_sess = PS_GET_MOD_DATA();

if (!memc_sess) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
return FAILURE;
}

memcached_delete(memc_sess->memc_sess, key->val, key->len, 0);
if (MEMC_G(sess_locking_enabled)) {
php_memc_sess_unlock(memc_sess->memc_sess);
Expand Down