summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-11-06 12:33:42 +0100
committerantirez <antirez@gmail.com>2017-11-06 12:37:03 +0100
commita1944c3e4d2fb2b5aef7c6c3efc769ef2edd71ee (patch)
tree52b671c93b4e6ccd74c550215a061046f807310e
parent34d5804d4c85d077b6af6265ebd86f35ecca89de (diff)
downloadredis-a1944c3e4d2fb2b5aef7c6c3efc769ef2edd71ee.tar.gz
Fix saving of zero-length lists.
Normally in modern Redis you can't create zero-len lists, however it's possible to load them from old RDB files generated, for instance, using Redis 2.8 (see issue #4409). The "Right Thing" would be not loading such lists at all, but this requires to hook in rdb.c random places in a not great way, for a problem that is at this point, at best, minor. Here in this commit instead I just fix the fact that zero length lists, materialized as quicklists with the first node set to NULL, were iterated in the wrong way while they are saved, leading to a crash. The other parts of the list implementation are apparently able to deal with empty lists correctly, even if they are no longer a thing.
-rw-r--r--src/rdb.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/rdb.c b/src/rdb.c
index 125df6071..36e4400f4 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -656,7 +656,7 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) {
if ((n = rdbSaveLen(rdb,ql->len)) == -1) return -1;
nwritten += n;
- do {
+ while(node) {
if (quicklistNodeIsCompressed(node)) {
void *data;
size_t compress_len = quicklistGetLzf(node, &data);
@@ -666,7 +666,8 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) {
if ((n = rdbSaveRawString(rdb,node->zl,node->sz)) == -1) return -1;
nwritten += n;
}
- } while ((node = node->next));
+ node = node->next;
+ }
} else {
serverPanic("Unknown list encoding");
}