Skip to content

Commit a39684b

Browse files
chendq8oranagrachendianqiangenjoy-binbin
authored andcommitted
fix hincrbyfloat not to create a key if the new value is invalid (redis#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 <[email protected]> Co-authored-by: chendianqiang <[email protected]> Co-authored-by: Binbin <[email protected]>
1 parent 21eabc7 commit a39684b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/t_hash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ void hincrbyfloatCommand(client *c) {
666666
unsigned int vlen;
667667

668668
if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
669+
if (isnan(incr) || isinf(incr)) {
670+
addReplyError(c,"value is NaN or Infinity");
671+
return;
672+
}
669673
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
670674
if (hashTypeGetValue(o,c->argv[2]->ptr,&vstr,&vlen,&ll) == C_OK) {
671675
if (vstr) {

tests/unit/type/hash.tcl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,4 +819,8 @@ start_server {tags {"hash"}} {
819819
set _ $k
820820
} {ZIP_INT_8B 127 ZIP_INT_16B 32767 ZIP_INT_32B 2147483647 ZIP_INT_64B 9223372036854775808 ZIP_INT_IMM_MIN 0 ZIP_INT_IMM_MAX 12}
821821

822+
test {HINCRBYFLOAT does not allow NaN or Infinity} {
823+
assert_error "*value is NaN or Infinity*" {r hincrbyfloat hfoo field +inf}
824+
assert_equal 0 [r exists hfoo]
825+
}
822826
}

0 commit comments

Comments
 (0)