summaryrefslogtreecommitdiff
path: root/src/ziplist.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2021-01-31 12:13:45 +0200
committerGitHub <noreply@github.com>2021-01-31 12:13:45 +0200
commit5a7eb9c8810980c4a3e453d9f9fa6d19ab832062 (patch)
tree3bc74a25a61482b7c36be7ff6e61c0074b162f7b /src/ziplist.c
parenteacccd2acbbebde3e50e14a4d0ade5b1ccc2bc07 (diff)
downloadredis-5a7eb9c8810980c4a3e453d9f9fa6d19ab832062.tar.gz
Fix test issues from introduction of HRANDFIELD (#8424)
* The corrupt dump fuzzer found a division by zero. * in some cases the random fields from the HRANDFIELD tests produced fields with newlines and other special chars (due to \ char), this caused the TCL tests to see a bulk response that has a newline in it and add {} around it, later it can think this is a nested list. in fact the `alpha` random string generator isn't using spaces and newlines, so it should not use `\` either.
Diffstat (limited to 'src/ziplist.c')
-rw-r--r--src/ziplist.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/ziplist.c b/src/ziplist.c
index 62ffcb93d..0cd20630a 100644
--- a/src/ziplist.c
+++ b/src/ziplist.c
@@ -1506,6 +1506,9 @@ void ziplistRandomPair(unsigned char *zl, unsigned long total_count, ziplistEntr
int ret;
unsigned char *p;
+ /* Avoid div by zero on corrupt ziplist */
+ assert(total_count);
+
/* Generate even numbers, because ziplist saved K-V pair */
int r = (rand() % total_count) * 2;
p = ziplistIndex(zl, r);
@@ -1545,6 +1548,9 @@ void ziplistRandomPairs(unsigned char *zl, int count, ziplistEntry *keys, ziplis
rand_pick *picks = zmalloc(sizeof(rand_pick)*count);
unsigned long total_size = ziplistLen(zl)/2;
+ /* Avoid div by zero on corrupt ziplist */
+ assert(total_size);
+
/* create a pool of random indexes (some may be duplicate). */
for (int i = 0; i < count; i++) {
picks[i].index = (rand() % total_size) * 2; /* Generate even indexes */