summaryrefslogtreecommitdiffstats
path: root/redis-pr1063.patch
blob: 0c4d68d806de592a516d90c1a8f562c0af977e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 18c7ab007649f068075880984e59938b849b5ab5 Mon Sep 17 00:00:00 2001
From: Remi Collet <fedora@famillecollet.com>
Date: Fri, 16 Dec 2016 15:29:05 +0100
Subject: [PATCH] fix #1062 restore 3.0.0 session behavior for PHP 7.1

---
 redis_session.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/redis_session.c b/redis_session.c
index 6faae20..2ac2872 100644
--- a/redis_session.c
+++ b/redis_session.c
@@ -360,7 +360,7 @@ PS_READ_FUNC(redis)
     resp = redis_session_key(rpm, key->val, key->len, &resp_len);
 #endif
     cmd_len = redis_cmd_format_static(&cmd, "GET", "s", resp, resp_len);
-    
+
     efree(resp);
     if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
         efree(cmd);
@@ -368,15 +368,26 @@ PS_READ_FUNC(redis)
     }
     efree(cmd);
 
-    /* read response */
-    if ((resp = redis_sock_read(redis_sock, &resp_len TSRMLS_CC)) == NULL) {
+    /* Read response from Redis.  If we get a NULL response from redis_sock_read
+     * this can indicate an error, OR a "NULL bulk" reply (empty session data)
+     * in which case we can reply with success. */
+    if ((resp = redis_sock_read(redis_sock, &resp_len TSRMLS_CC)) == NULL && resp_len != -1) {
         return FAILURE;
     }
 #if (PHP_MAJOR_VERSION < 7)
-    *val = resp;
-    *vallen = resp_len;
+    if (resp_len < 0) {
+        *val = STR_EMPTY_ALLOC();
+        *vallen = 0;
+    } else {
+        *val = resp;
+        *vallen = resp_len;
+    }
 #else
-    *val = zend_string_init(resp, resp_len, 0);
+    if (resp_len < 0) {
+        *val = ZSTR_EMPTY_ALLOC();
+    } else {
+        *val = zend_string_init(resp, resp_len, 0);
+    }
     efree(resp);
 #endif