diff --git a/src/t_hash.c b/src/t_hash.c index a2af438ae..9ebd99ccc 100644 --- a/src/t_hash.c +++ b/src/t_hash.c @@ -1120,8 +1120,13 @@ void hrandfieldCommand(client *c) { if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withvalues"))) { addReplyErrorObject(c,shared.syntaxerr); return; - } else if (c->argc == 4) + } else if (c->argc == 4) { withvalues = 1; + if (l < LONG_MIN/2 || l > LONG_MAX/2) { + addReplyError(c,"value is out of range"); + return; + } + } hrandfieldWithCountCommand(c, l, withvalues); return; } diff --git a/src/t_zset.c b/src/t_zset.c index 5dadd58fd..e0d8509cf 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -4317,8 +4317,13 @@ void zrandmemberCommand(client *c) { if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withscores"))) { addReplyErrorObject(c,shared.syntaxerr); return; - } else if (c->argc == 4) + } else if (c->argc == 4) { withscores = 1; + if (l < LONG_MIN/2 || l > LONG_MAX/2) { + addReplyError(c,"value is out of range"); + return; + } + } zrandmemberWithCountCommand(c, l, withscores); return; } diff --git a/tests/unit/type/hash.tcl b/tests/unit/type/hash.tcl index e7b9f3d85..113780ff7 100644 --- a/tests/unit/type/hash.tcl +++ b/tests/unit/type/hash.tcl @@ -71,6 +71,11 @@ start_server {tags {"hash"}} { r hrandfield myhash 0 } {} + test "HRANDFIELD count overflow" { + r hmset myhash a 1 + assert_error {*value is out of range*} {r hrandfield myhash -9223372036854770000 withvalues} + } {} + test "HRANDFIELD with against non existing key" { r hrandfield nonexisting_key 100 } {} diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl index 41898f27b..036638510 100644 --- a/tests/unit/type/zset.tcl +++ b/tests/unit/type/zset.tcl @@ -2322,6 +2322,11 @@ start_server {tags {"zset"}} { r zrandmember nonexisting_key 100 } {} + test "ZRANDMEMBER count overflow" { + r zadd myzset 0 a + assert_error {*value is out of range*} {r zrandmember myzset -9223372036854770000 withscores} + } {} + # Make sure we can distinguish between an empty array and a null response r readraw 1