mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Disable negative offsets for SETRANGE
This commit is contained in:
parent
e983cf34be
commit
8f8eeffec1
@ -195,11 +195,13 @@ void setrangeCommand(redisClient *c) {
|
||||
if (getLongFromObjectOrReply(c,c->argv[2],&offset,NULL) != REDIS_OK)
|
||||
return;
|
||||
|
||||
if (offset < 0) {
|
||||
addReplyError(c,"offset is out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
o = lookupKeyWrite(c->db,c->argv[1]);
|
||||
if (o == NULL) {
|
||||
/* Negative offset is always 0 for non-existing keys */
|
||||
if (offset < 0) offset = 0;
|
||||
|
||||
/* Return 0 when setting nothing on a non-existing string */
|
||||
if (sdslen(value) == 0) {
|
||||
addReply(c,shared.czero);
|
||||
@ -233,15 +235,6 @@ void setrangeCommand(redisClient *c) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Convert negative indexes. Note that for SETRANGE, the meaning of a
|
||||
* negative index is a little different than for other commands.
|
||||
* Here, an offset of -1 points to the trailing NULL byte of the
|
||||
* string instead of the last character. */
|
||||
if (offset < 0) {
|
||||
offset = olen+1+offset;
|
||||
if (offset < 0) offset = 0;
|
||||
}
|
||||
|
||||
/* Return when the resulting string exceeds allowed size */
|
||||
if (checkStringLength(c,offset+sdslen(value)) != REDIS_OK)
|
||||
return;
|
||||
|
@ -489,14 +489,6 @@ start_server {tags {"basic"}} {
|
||||
r del mykey
|
||||
assert_equal 4 [r setrange mykey 1 foo]
|
||||
assert_equal "\000foo" [r get mykey]
|
||||
|
||||
r del mykey
|
||||
assert_equal 3 [r setrange mykey -1 foo]
|
||||
assert_equal "foo" [r get mykey]
|
||||
|
||||
r del mykey
|
||||
assert_equal 3 [r setrange mykey -100 foo]
|
||||
assert_equal "foo" [r get mykey]
|
||||
}
|
||||
|
||||
test "SETRANGE against string-encoded key" {
|
||||
@ -512,18 +504,6 @@ start_server {tags {"basic"}} {
|
||||
assert_equal 3 [r setrange mykey 1 b]
|
||||
assert_equal "fbo" [r get mykey]
|
||||
|
||||
r set mykey "foo"
|
||||
assert_equal 6 [r setrange mykey -1 bar]
|
||||
assert_equal "foobar" [r get mykey]
|
||||
|
||||
r set mykey "foo"
|
||||
assert_equal 5 [r setrange mykey -2 bar]
|
||||
assert_equal "fobar" [r get mykey]
|
||||
|
||||
r set mykey "foo"
|
||||
assert_equal 3 [r setrange mykey -20 bar]
|
||||
assert_equal "bar" [r get mykey]
|
||||
|
||||
r set mykey "foo"
|
||||
assert_equal 7 [r setrange mykey 4 bar]
|
||||
assert_equal "foo\000bar" [r get mykey]
|
||||
@ -549,18 +529,6 @@ start_server {tags {"basic"}} {
|
||||
assert_encoding raw mykey
|
||||
assert_equal 1334 [r get mykey]
|
||||
|
||||
r set mykey 1234
|
||||
assert_encoding int mykey
|
||||
assert_equal 5 [r setrange mykey -1 5]
|
||||
assert_encoding raw mykey
|
||||
assert_equal 12345 [r get mykey]
|
||||
|
||||
r set mykey 1234
|
||||
assert_encoding int mykey
|
||||
assert_equal 4 [r setrange mykey -2 5]
|
||||
assert_encoding raw mykey
|
||||
assert_equal 1235 [r get mykey]
|
||||
|
||||
r set mykey 1234
|
||||
assert_encoding int mykey
|
||||
assert_equal 6 [r setrange mykey 5 2]
|
||||
@ -577,7 +545,9 @@ start_server {tags {"basic"}} {
|
||||
test "SETRANGE with out of range offset" {
|
||||
r del mykey
|
||||
assert_error "*maximum allowed size*" {r setrange mykey [expr 512*1024*1024-4] world}
|
||||
|
||||
r set mykey "hello"
|
||||
assert_error "*out of range*" {r setrange mykey -1 world}
|
||||
assert_error "*maximum allowed size*" {r setrange mykey [expr 512*1024*1024-4] world}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user