Commit 3e0d2096 authored by Valentino Geron's avatar Valentino Geron Committed by antirez
Browse files

XREAD and XREADGROUP should not be allowed from scripts when BLOCK option is being used

parent 240094c9
...@@ -947,11 +947,11 @@ struct redisCommand redisCommandTable[] = { ...@@ -947,11 +947,11 @@ struct redisCommand redisCommandTable[] = {
0,NULL,1,1,1,0,0,0}, 0,NULL,1,1,1,0,0,0},
{"xread",xreadCommand,-4, {"xread",xreadCommand,-4,
"read-only no-script @stream @blocking", "read-only @stream @blocking",
0,xreadGetKeys,1,1,1,0,0,0}, 0,xreadGetKeys,1,1,1,0,0,0},
{"xreadgroup",xreadCommand,-7, {"xreadgroup",xreadCommand,-7,
"write no-script @stream @blocking", "write @stream @blocking",
0,xreadGetKeys,1,1,1,0,0,0}, 0,xreadGetKeys,1,1,1,0,0,0},
{"xgroup",xgroupCommand,-2, {"xgroup",xgroupCommand,-2,
......
...@@ -1374,6 +1374,11 @@ void xreadCommand(client *c) { ...@@ -1374,6 +1374,11 @@ void xreadCommand(client *c) {
int moreargs = c->argc-i-1; int moreargs = c->argc-i-1;
char *o = c->argv[i]->ptr; char *o = c->argv[i]->ptr;
if (!strcasecmp(o,"BLOCK") && moreargs) { if (!strcasecmp(o,"BLOCK") && moreargs) {
if (c->flags & CLIENT_LUA) {
/* There is no sense to use BLOCK option within LUA */
addReplyErrorFormat(c, "%s command is not allowed with BLOCK option from scripts", (char *)c->argv[0]->ptr);
return;
}
i++; i++;
if (getTimeoutFromObjectOrReply(c,c->argv[i],&timeout, if (getTimeoutFromObjectOrReply(c,c->argv[i],&timeout,
UNIT_MILLISECONDS) != C_OK) return; UNIT_MILLISECONDS) != C_OK) return;
......
...@@ -146,6 +146,17 @@ start_server {tags {"scripting"}} { ...@@ -146,6 +146,17 @@ start_server {tags {"scripting"}} {
set e set e
} {*not allowed*} } {*not allowed*}
test {EVAL - Scripts can't run XREAD and XREADGROUP with BLOCK option} {
r del s
r xgroup create s g $ MKSTREAM
set res [r eval {return redis.pcall('xread','STREAMS','s','$')} 1 s]
assert {$res eq {}}
assert_error "*xread command is not allowed with BLOCK option from scripts" {r eval {return redis.pcall('xread','BLOCK',0,'STREAMS','s','$')} 1 s}
set res [r eval {return redis.pcall('xreadgroup','group','g','c','STREAMS','s','>')} 1 s]
assert {$res eq {}}
assert_error "*xreadgroup command is not allowed with BLOCK option from scripts" {r eval {return redis.pcall('xreadgroup','group','g','c','BLOCK',0,'STREAMS','s','>')} 1 s}
}
test {EVAL - Scripts can't run certain commands} { test {EVAL - Scripts can't run certain commands} {
set e {} set e {}
r debug lua-always-replicate-commands 0 r debug lua-always-replicate-commands 0
......
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