|
|
d864f0 |
Backported for 5.0.3
|
|
|
d864f0 |
|
|
|
d864f0 |
|
|
|
d864f0 |
|
|
|
d864f0 |
From 48f04a82a0ac542341fb644a4cfbebadd5c59a33 Mon Sep 17 00:00:00 2001
|
|
|
d864f0 |
From: Yossi Gottlieb <yossigo@gmail.com>
|
|
|
d864f0 |
Date: Mon, 22 Feb 2021 15:41:32 +0200
|
|
|
d864f0 |
Subject: [PATCH] Fix integer overflow (CVE-2021-21309). (#8522)
|
|
|
d864f0 |
|
|
|
d864f0 |
On 32-bit systems, setting the proto-max-bulk-len config parameter to a high value may result with integer overflow and a subsequent heap overflow when parsing an input bulk (CVE-2021-21309).
|
|
|
d864f0 |
|
|
|
d864f0 |
This fix has two parts:
|
|
|
d864f0 |
|
|
|
d864f0 |
Set a reasonable limit to the config parameter.
|
|
|
d864f0 |
Add additional checks to prevent the problem in other potential but unknown code paths.
|
|
|
d864f0 |
|
|
|
d864f0 |
(cherry picked from commit d32f2e9999ce003bad0bd2c3bca29f64dcce4433)
|
|
|
d864f0 |
|
|
|
d864f0 |
Fix MSVR reported issue.
|
|
|
d864f0 |
---
|
|
|
d864f0 |
src/config.c | 16 ++++++++--------
|
|
|
d864f0 |
src/sds.c | 3 +++
|
|
|
d864f0 |
src/zmalloc.c | 10 ++++++++++
|
|
|
d864f0 |
3 files changed, 21 insertions(+), 8 deletions(-)
|
|
|
d864f0 |
|
|
|
d864f0 |
diff --git a/src/sds.c b/src/sds.c
|
|
|
d864f0 |
index cd60946bdd32..12c9da356d9b 100644
|
|
|
d864f0 |
--- a/src/sds.c
|
|
|
d864f0 |
+++ b/src/sds.c
|
|
|
d864f0 |
@@ -96,6 +96,7 @@ sds sdsnewlen(const void *init, size_t initlen) {
|
|
|
d864f0 |
int hdrlen = sdsHdrSize(type);
|
|
|
d864f0 |
unsigned char *fp; /* flags pointer. */
|
|
|
d864f0 |
|
|
|
d864f0 |
+ assert(hdrlen+initlen+1 > initlen); /* Catch size_t overflow */
|
|
|
d864f0 |
sh = s_malloc(hdrlen+initlen+1);
|
|
|
d864f0 |
if (init==SDS_NOINIT)
|
|
|
d864f0 |
init = NULL;
|
|
|
d864f0 |
@@ -214,6 +215,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
|
|
|
d864f0 |
len = sdslen(s);
|
|
|
d864f0 |
sh = (char*)s-sdsHdrSize(oldtype);
|
|
|
d864f0 |
newlen = (len+addlen);
|
|
|
d864f0 |
+ assert(newlen > len); /* Catch size_t overflow */
|
|
|
d864f0 |
if (newlen < SDS_MAX_PREALLOC)
|
|
|
d864f0 |
newlen *= 2;
|
|
|
d864f0 |
else
|
|
|
d864f0 |
@@ -227,6 +229,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
|
|
|
d864f0 |
if (type == SDS_TYPE_5) type = SDS_TYPE_8;
|
|
|
d864f0 |
|
|
|
d864f0 |
hdrlen = sdsHdrSize(type);
|
|
|
d864f0 |
+ assert(hdrlen+newlen+1 > len); /* Catch size_t overflow */
|
|
|
d864f0 |
if (oldtype==type) {
|
|
|
d864f0 |
newsh = s_realloc(sh, hdrlen+newlen+1);
|
|
|
d864f0 |
if (newsh == NULL) return NULL;
|
|
|
d864f0 |
|
|
|
d864f0 |
From 2b0ac7427ba5a6e1bc89380e960b138af893bbdd Mon Sep 17 00:00:00 2001
|
|
|
d864f0 |
From: YiyuanGUO <yguoaz@gmail.com>
|
|
|
d864f0 |
Date: Wed, 29 Sep 2021 10:20:35 +0300
|
|
|
d864f0 |
Subject: [PATCH] Fix integer overflow in _sdsMakeRoomFor (CVE-2021-41099)
|
|
|
d864f0 |
|
|
|
d864f0 |
---
|
|
|
d864f0 |
src/sds.c | 6 +++---
|
|
|
d864f0 |
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
d864f0 |
|
|
|
d864f0 |
diff --git a/src/sds.c b/src/sds.c
|
|
|
d864f0 |
index 12c9da356d9b..73d9807ae3c0 100644
|
|
|
d864f0 |
--- a/src/sds.c
|
|
|
d864f0 |
+++ b/src/sds.c
|
|
|
d864f0 |
@@ -205,7 +205,7 @@ void sdsclear(sds s) {
|
|
|
d864f0 |
sds sdsMakeRoomFor(sds s, size_t addlen) {
|
|
|
d864f0 |
void *sh, *newsh;
|
|
|
d864f0 |
size_t avail = sdsavail(s);
|
|
|
d864f0 |
- size_t len, newlen;
|
|
|
d864f0 |
+ size_t len, newlen, reqlen;
|
|
|
d864f0 |
char type, oldtype = s[-1] & SDS_TYPE_MASK;
|
|
|
d864f0 |
int hdrlen;
|
|
|
d864f0 |
|
|
|
d864f0 |
@@ -214,7 +214,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
|
|
|
d864f0 |
|
|
|
d864f0 |
len = sdslen(s);
|
|
|
d864f0 |
sh = (char*)s-sdsHdrSize(oldtype);
|
|
|
d864f0 |
- newlen = (len+addlen);
|
|
|
d864f0 |
+ reqlen = newlen = (len+addlen);
|
|
|
d864f0 |
assert(newlen > len); /* Catch size_t overflow */
|
|
|
d864f0 |
if (newlen < SDS_MAX_PREALLOC)
|
|
|
d864f0 |
newlen *= 2;
|
|
|
d864f0 |
@@ -229,7 +229,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
|
|
|
d864f0 |
if (type == SDS_TYPE_5) type = SDS_TYPE_8;
|
|
|
d864f0 |
|
|
|
d864f0 |
hdrlen = sdsHdrSize(type);
|
|
|
d864f0 |
- assert(hdrlen+newlen+1 > len); /* Catch size_t overflow */
|
|
|
d864f0 |
+ assert(hdrlen + newlen + 1 > reqlen); /* Catch size_t overflow */
|
|
|
d864f0 |
if (oldtype==type) {
|
|
|
d864f0 |
newsh = s_realloc(sh, hdrlen+newlen+1);
|
|
|
d864f0 |
if (newsh == NULL) return NULL;
|