Skip to content

Commit 6f6cd68

Browse files
Attempt to solve the problem where empty session data returns
an error when reading.
1 parent 2e5a710 commit 6f6cd68

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

library.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
518518
case '*':
519519
/* For null multi-bulk replies (like timeouts from brpoplpush): */
520520
if(memcmp(inbuf + 1, "-1", 2) == 0) {
521+
*buf_len = -1;
521522
return NULL;
522523
}
523524
/* fall through */

redis_session.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ PS_READ_FUNC(redis)
338338
char *session, *cmd;
339339
int session_len, cmd_len;
340340
char *char_val;
341-
int int_val;
341+
int int_val = 0;
342342

343343
redis_pool *pool = PS_GET_MOD_DATA();
344344
redis_pool_member *rpm = redis_pool_get_sock(pool, key->val);
@@ -358,11 +358,17 @@ PS_READ_FUNC(redis)
358358
}
359359
efree(cmd);
360360

361-
/* read response */
362-
if ((char_val = redis_sock_read(redis_sock, &int_val)) == NULL) {
361+
/* Read response from Redis. If we get a NULL response from redis_sock_read
362+
* this can indicate an error, OR a "NULL bulk" reply (empty session data)
363+
* in which case we can reply with success. */
364+
if ((char_val = redis_sock_read(redis_sock, &int_val)) == NULL && int_val != -1)
365+
{
363366
return FAILURE;
364367
}
365-
*val = zend_string_init(char_val, int_val, 0);
368+
369+
*val = zend_string_init(char_val, int_val == -1 ? 0 : int_val, 0);
370+
if (char_val) efree(char_val);
371+
366372
return SUCCESS;
367373
}
368374
/* }}} */

0 commit comments

Comments
 (0)