Skip to content

Commit 7df23a5

Browse files
chendq8oranagrachendianqiangenjoy-binbin
committed
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 <[email protected]> Co-authored-by: chendianqiang <[email protected]> Co-authored-by: Binbin <[email protected]> (cherry picked from commit bc7fe41) (cherry picked from commit 606a385)
1 parent 720ea82 commit 7df23a5

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
@@ -729,6 +729,10 @@ void hincrbyfloatCommand(client *c) {
729729
unsigned int vlen;
730730

731731
if (getLongDoubleFromObjectOrReply(c,c->argv[3],&incr,NULL) != C_OK) return;
732+
if (isnan(incr) || isinf(incr)) {
733+
addReplyError(c,"value is NaN or Infinity");
734+
return;
735+
}
732736
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
733737
if (hashTypeGetValue(o,c->argv[2]->ptr,&vstr,&vlen,&ll) == C_OK) {
734738
if (vstr) {

tests/unit/type/hash.tcl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,8 @@ start_server {tags {"hash"}} {
801801
set _ $k
802802
} {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}
803803

804+
test {HINCRBYFLOAT does not allow NaN or Infinity} {
805+
assert_error "*value is NaN or Infinity*" {r hincrbyfloat hfoo field +inf}
806+
assert_equal 0 [r exists hfoo]
807+
}
804808
}

0 commit comments

Comments
 (0)