Unverified Commit 063de675 authored by Binbin's avatar Binbin Committed by GitHub
Browse files

zunionInterDiffGenericCommand use ztrycalloc to avoid OOM panic (#13052)

In low memory situations, sending a big number of arguments (sets)
may cause OOM panic. Use ztrycalloc, like we do on LCS and XAUTOCLAIM,
and fail gracefully.

This change affects the following commands: ZUNION, ZINTER, ZDIFF,
ZUNIONSTORE, ZINTERSTORE, ZDIFFSTORE, ZINTERCARD.
parent 32f44da5
...@@ -2663,8 +2663,14 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in ...@@ -2663,8 +2663,14 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in
return; return;
} }
/* Try to allocate the src table, and abort on insufficient memory. */
src = ztrycalloc(sizeof(zsetopsrc) * setnum);
if (src == NULL) {
addReplyError(c, "Insufficient memory, failed allocating transient memory, too many args.");
return;
}
/* read keys to be used for input */ /* read keys to be used for input */
src = zcalloc(sizeof(zsetopsrc) * setnum);
for (i = 0, j = numkeysIndex+1; i < setnum; i++, j++) { for (i = 0, j = numkeysIndex+1; i < setnum; i++, j++) {
robj *obj = lookupKeyRead(c->db, c->argv[j]); robj *obj = lookupKeyRead(c->db, c->argv[j]);
if (obj != NULL) { if (obj != NULL) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment