Skip to content

Commit 23112fa

Browse files
ranshidmadolson
andauthored
fix hsetex handling of wrong number of fields (valkey-io#2509)
currently hsetex is verifying the number of fields matches the provided number of fields by using div. instead it can match to the multiplication in order to prevent rounding the verified value down. --------- Signed-off-by: Ran Shidlansik <ranshid@amazon.com> Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
1 parent 39d5c6e commit 23112fa

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/t_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ void hsetexCommand(client *c) {
12001200
}
12011201
}
12021202
/* Check that the parsed fields number matches the real provided number of fields */
1203-
if (!num_fields || num_fields != (c->argc - fields_index) / 2) {
1203+
if (!num_fields || num_fields > LLONG_MAX / 2 || (num_fields * 2) != (c->argc - fields_index)) {
12041204
addReplyError(c, "numfields should be greater than 0 and match the provided number of fields");
12051205
return;
12061206
}

tests/unit/hashexpire.tcl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,9 @@ start_server {tags {"hashexpire"}} {
623623
set e
624624
} {ERR *}
625625

626-
# test {HSETEX PX - mismatched field/value count} {
627-
# catch {r HSETEX myhash PX 100 FIELDS 2 field1 val1} e
628-
# set e
629-
# } {ERR wrong number of arguments for 'hsetex' command}
626+
test {HSETEX PX - mismatched field/value count} {
627+
assert_error {ERR numfields should be greater than 0 and match the provided number of fields} {r HSETEX myhash PX 100 FIELDS 1 field1 val1 extra}
628+
}
630629

631630

632631
## FNX/FXX

0 commit comments

Comments
 (0)