mirror of https://mirror.osredm.com/root/redis.git
fix hincrbyfloat not to create a key if the new value is invalid (#11149)
Check the validity of the value before performing the create operation, prevents new data from being generated even if the request fails to execute. Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: chendianqiang <chendianqiang@meituan.com> Co-authored-by: Binbin <binloveplay1314@qq.com> (cherry picked from commitbc7fe41e58
) (cherry picked from commit606a385935
) (cherry picked from commit7df23a5f51
)
This commit is contained in:
parent
ebe2e4583f
commit
c924ac3fdf
|
@ -605,6 +605,10 @@ void hincrbyfloatCommand(client *c) {
|
|||
unsigned int vlen;
|
||||
|
||||
if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
|
||||
if (isnan(incr) || isinf(incr)) {
|
||||
addReplyError(c,"value is NaN or Infinity");
|
||||
return;
|
||||
}
|
||||
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
|
||||
if (hashTypeGetValue(o,c->argv[2]->ptr,&vstr,&vlen,&ll) == C_OK) {
|
||||
if (vstr) {
|
||||
|
|
|
@ -540,4 +540,9 @@ start_server {tags {"hash"}} {
|
|||
assert {[r hincrbyfloat myhash float -0.1] eq {1.9}}
|
||||
}
|
||||
}
|
||||
|
||||
test {HINCRBYFLOAT does not allow NaN or Infinity} {
|
||||
assert_error "*value is NaN or Infinity*" {r hincrbyfloat hfoo field +inf}
|
||||
assert_equal 0 [r exists hfoo]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue