Skip to content

Commit

Permalink
Merge pull request #126 from qiongtubao/fix/command_params_error
Browse files Browse the repository at this point in the history
[fix] Command parameter length is incorrect
  • Loading branch information
qiongtubao authored Feb 4, 2021
2 parents 3af49bd + 8f4c0aa commit 6a9371d
Show file tree
Hide file tree
Showing 14 changed files with 803 additions and 410 deletions.
7 changes: 7 additions & 0 deletions CRDT-RELEASENOTES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ MODERATE: Program an upgrade of the server, but it's not urgent.
HIGH: There is a critical bug that may affect a subset of users. Upgrade!
CRITICAL: There is a critical bug affecting MOST USERS. Upgrade ASAP.
--------------------------------------------------------------------------------
================================================================================
XRedis-CRDT 1.0.10 Released Thu Feb 4 14:31:37 CST 2021
================================================================================
Upgrade urgency HIGH: Compared with the previous version, there are some improvements, mainly:
Major things:
* [bugfix] redis-server crash when the zrange command uses wrong parameters

================================================================================
XRedis-CRDT 1.0.9 Released Sun Dec 13 23:42:49 CST 2020
================================================================================
Expand Down
2 changes: 1 addition & 1 deletion package.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP=xredis-crdt
Version=1.0.9
Version=1.0.10
Package=$APP-$Version

find . -name ctrip.h -exec sed -i "s/XREDIS_CRDT_VERSION \"\(.*\)\"/XREDIS_CRDT_VERSION \"$Version\"/" {} \;
Expand Down
2 changes: 1 addition & 1 deletion src/ctrip.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef SRC_CTRIP_H_
#define SRC_CTRIP_H_

#define XREDIS_CRDT_VERSION "1.0.9"
#define XREDIS_CRDT_VERSION "1.0.10"
#define CONFIG_DEFAULT_SLAVE_REPLICATE_ALL 0

void xslaveofCommand(client *c);
Expand Down
2 changes: 1 addition & 1 deletion src/ctrip_crdt_rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ int data2CrdtData(client* fakeClient,robj* key, robj* val) {
double score = zzlGetScore(sptr);
fakeClient->argv[i++] = createStringObjectFromLongDouble((long double)score, 1);
zzlNext(zl,&eptr,&sptr);
fakeClient->argv[i++] = createRawStringObject(vstr, vlen);
fakeClient->argv[i++] = createObject(OBJ_STRING, sdsnewlen(vstr,vlen));
len--;
} while (eptr != NULL && i < MAX_FAKECLIENT_ARGV);
fakeClient->argc = i;
Expand Down
2 changes: 1 addition & 1 deletion src/ctrip_crdt_replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,4 +1953,4 @@ void crdtReplicationCommand(client *c) {
}
addReplyBulkCBuffer(c, s, sdslen(s));
sdsfree(s);
}
}
7 changes: 4 additions & 3 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,18 @@ static void zsetKeyReset(RedisModuleKey *key);
#include <stdio.h>
#include <execinfo.h>
#define STACK_SIZE 1000
static void debug_memory(size_t memory, size_t num)
__attribute__((unused)) static void debug_memory(size_t memory, size_t num)
{
void *trace[STACK_SIZE];
size_t size = backtrace(trace, STACK_SIZE);
num = min(num, size - 1);
char **symbols = (char **)backtrace_symbols(trace,size);
for (size_t i = 0; i<num; i++) {
printf("%d--->%s\n", i, symbols[i+1]);
printf("%zu--->%s\n", i, symbols[i+1]);
}
printf("use memory:[%zu]\n", memory);
free(symbols);
//./src/server.h:2188:42 'free' has been explicitly marked deprecated here
// free(symbols);
return;
}
/* Use like malloc(). Memory allocated with this function is reported in
Expand Down
2 changes: 1 addition & 1 deletion src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ int processMultibulkBuffer(client *c) {
}

void printCommand(client *c) {
sds command = (sds)c->argv[0]->ptr;
// sds command = (sds)c->argv[0]->ptr;
size_t max_buf = 1024;
char buf[max_buf];
int len = sprintf(buf, "cmd: ");
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3518,7 +3518,7 @@ sds genRedisInfoString(char *section, struct redisServer *srv) {
"peer%d_host:%s\r\n"
"peer%d_port:%d\r\n"
"peer%d_gid:%lld\r\n"
"peer%d_dbid:%lld\r\n"
"peer%d_dbid:%d\r\n"
"peer%d_link_status:%s\r\n"
"peer%d_last_io_seconds_ago:%d\r\n"
"peer%d_sync_in_progress:%d\r\n"
Expand Down
Binary file modified tests/assets/mac/crdt.so
Binary file not shown.
92 changes: 92 additions & 0 deletions tests/ctrip/unit/crdt_hash.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,98 @@ proc decode_binary_str {binary_str size} {
binary scan $binary_str $type result
return $result
}
start_server {tags {"crdt-hash"} overrides {crdt-gid 1} config {crdt.conf} module {crdt.so}} {
set master [srv 0 client]
set master_gid 1
set master_host [srv 0 host]
set master_port [srv 0 port]
set master_log [srv 0 stdout]
proc params_error {script} {
catch {[uplevel 1 $script ]} result opts
# puts $result
assert_match "*ERR wrong number of arguments for '*' command*" $result
}
test "params_error" {
params_error {
$master hset k
}
params_error {
$master hdel k
}
params_error {
$master hscan k
}
params_error {
$master hmset k
}
params_error {
$master hget k
}
params_error {
$master hmget k
}
params_error {
$master del
}
params_error {
$master HGETALL
}
params_error {
$master hkeys
}
params_error {
$master hvals
}
params_error {
$master hlen
}
params_error {
$master hscan
}
}
proc type_error {script} {
catch {[uplevel 1 $script ]} result opts
assert_match "*WRONGTYPE Operation against a key holding the wrong kind of value*" $result
}
test "type_error" {
r set hash a
type_error {
$master hset hash k v
}
type_error {
$master hdel hash k v
}
type_error {
$master hscan hash 0
}
type_error {
$master hmset hash k v k1 v2
}
type_error {
$master hget hash k
}
type_error {
$master hmget hash k
}
type_error {
$master hgetall hash
}
type_error {
$master hkeys hash
}
type_error {
$master hvals hash
}
type_error {
$master hscan hash 0
}
type_error {
$master hlen hash
}
assert_equal [r get hash] a
}
}

start_server {tags {"crdt-hash"} overrides {crdt-gid 1} config {crdt.conf} module {crdt.so}} {

set redis_host [srv 0 host]
Expand Down
72 changes: 72 additions & 0 deletions tests/ctrip/unit/crdt_set.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,78 @@ proc wait { client index type log} {
error "assertion: Master-Slave not correctly synchronized"
}
}

start_server {tags {"crdt-set"} overrides {crdt-gid 1} config {crdt.conf} module {crdt.so} } {
set master [srv 0 client]
set master_gid 1
set master_host [srv 0 host]
set master_port [srv 0 port]
set master_log [srv 0 stdout]
proc params_error {script} {
catch {[uplevel 1 $script ]} result opts
# puts $result
assert_match "*ERR wrong number of arguments for '*' command*" $result
}
test "params_error" {
params_error {
$master sadd
}
params_error {
$master sismember
}
params_error {
$master srem
}
params_error {
$master scard
}
params_error {
$master smembers
}
params_error {
$master sunion
}
params_error {
$master sscan
}
params_error {
$master spop
}

}
proc type_error {script} {
catch {[uplevel 1 $script ]} result opts
assert_match "*WRONGTYPE Operation against a key holding the wrong kind of value*" $result
}
test "type_error" {
r set mset a
type_error {
$master sadd mset a
}
type_error {
$master sismember mset a
}
type_error {
$master srem mset a
}
type_error {
$master scard mset
}
type_error {
$master smembers mset
}
type_error {
$master sunion mset mset1
}
type_error {
$master sscan mset 0
}
type_error {
$master spop mset
}
assert_equal [r get mset] a
}
}
start_server {tags {"crdt-set"} overrides {crdt-gid 1} config {crdt.conf} module {crdt.so} } {
set master [srv 0 client]
set master_gid 1
Expand Down
82 changes: 82 additions & 0 deletions tests/ctrip/unit/rc1.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,88 @@ proc wait { client index type log} {
error "assertion: Master-Slave not correctly synchronized"
}
}

start_server {tags {"crdt-set"} overrides {crdt-gid 1} config {crdt.conf} module {crdt.so} } {
set master [srv 0 client]
set master_gid 1
set master_host [srv 0 host]
set master_port [srv 0 port]
set master_log [srv 0 stdout]
proc params_error {script} {
catch {[uplevel 1 $script ]} result opts
# puts $result
assert_match "*ERR wrong number of arguments for '*' command*" $result
}
test "params" {
params_error {
$master get
}
params_error {
$master set
}
params_error {
$master incr
}
params_error {
$master decr
}
params_error {
$master incrbyfloat
}
params_error {
$master incrby
}
params_error {
$master setex
}
params_error {
$master setnx
}
params_error {
$master expire
}
params_error {
$master PERSIST
}
params_error {
$master pexpire
}
}
proc type_error {script} {
catch {[uplevel 1 $script ]} result opts
assert_match "*WRONGTYPE Operation against a key holding the wrong kind of value*" $result
}
test "type_error" {
$master hset k a b
type_error {
$master get k
}
type_error {
$master set k v
}
type_error {
$master incr k
}
type_error {
$master decr k
}
type_error {
$master incrbyfloat k 1.0
}
type_error {
$master incrby k 1
}
type_error {
$master setex k 10 a
}
assert_equal [$master hget k a ] b
}
test "setex" {
assert_equal [$master ttl exkey] -2
$master setex exkey 100 v
assert {[$master ttl exkey] != -1}
}
}
start_server {tags {"crdt-set"} overrides {crdt-gid 1} config {crdt.conf} module {crdt.so} } {
set master [srv 0 client]
set master_gid 1
Expand Down
Loading

0 comments on commit 6a9371d

Please sign in to comment.