Skip to content

Commit d68098e

Browse files
committed
check if session was allocated on PS_OPEN_FUNC
1 parent def716a commit d68098e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

php_memcached_session.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ PS_OPEN_FUNC(memcached)
270270
PS_CLOSE_FUNC(memcached)
271271
{
272272
memcached_sess *memc_sess = PS_GET_MOD_DATA();
273+
274+
if (!memc_sess) {
275+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
276+
return FAILURE;
277+
}
273278

274279
if (MEMC_G(sess_locking_enabled)) {
275280
php_memc_sess_unlock(memc_sess->memc_sess TSRMLS_CC);
@@ -300,6 +305,11 @@ PS_READ_FUNC(memcached)
300305
memcached_sess *memc_sess = PS_GET_MOD_DATA();
301306
size_t key_length;
302307

308+
if (!memc_sess) {
309+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
310+
return FAILURE;
311+
}
312+
303313
key_length = strlen(MEMC_G(sess_prefix)) + key_len + 5; // prefix + "lock."
304314
if (!key_length || key_length >= MEMCACHED_MAX_KEY) {
305315
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The session id is too long or contains illegal characters");
@@ -334,6 +344,11 @@ PS_WRITE_FUNC(memcached)
334344
memcached_return status;
335345
memcached_sess *memc_sess = PS_GET_MOD_DATA();
336346
size_t key_length;
347+
348+
if (!memc_sess) {
349+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
350+
return FAILURE;
351+
}
337352

338353
key_length = strlen(MEMC_G(sess_prefix)) + key_len + 5; // prefix + "lock."
339354
if (!key_length || key_length >= MEMCACHED_MAX_KEY) {
@@ -367,6 +382,11 @@ PS_DESTROY_FUNC(memcached)
367382
{
368383
memcached_sess *memc_sess = PS_GET_MOD_DATA();
369384

385+
if (!memc_sess) {
386+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session is not allocated, check session.save_path value");
387+
return FAILURE;
388+
}
389+
370390
memcached_delete(memc_sess->memc_sess, key, strlen(key), 0);
371391
if (MEMC_G(sess_locking_enabled)) {
372392
php_memc_sess_unlock(memc_sess->memc_sess TSRMLS_CC);

0 commit comments

Comments
 (0)