Skip to content

Fix FIELDS argument validation in HSETEX/HGETEX#14883

Merged
sundb merged 6 commits intoredis:unstablefrom
gentcys:fix/hsetex-multiple-fields
Mar 19, 2026
Merged

Fix FIELDS argument validation in HSETEX/HGETEX#14883
sundb merged 6 commits intoredis:unstablefrom
gentcys:fix/hsetex-multiple-fields

Conversation

@gentcys
Copy link
Copy Markdown
Contributor

@gentcys gentcys commented Mar 12, 2026

Fixes #14879

Improve validation of the FIELDS argument in HSETEX and HGETEX to ensure exactly one field is provided, rejecting both missing and multiple fields with consistent and accurate error messages.

Align behavior across both commands.


Note

Medium Risk
Tightens argument validation for HSETEX/HGETEX and the HEXPIRE-family parsers, which can change previously-accepted (but ambiguous) command forms into hard errors and may impact client compatibility.

Overview
Prevents ambiguous hash field-expiration invocations by enforcing that FIELDS is present exactly once.

parseHashFieldExpireArgs() now errors if FIELDS is specified multiple times and rejects calls that omit FIELDS entirely; the flexible parseHashCommandArgs() used by the HEXPIRE family similarly rejects missing FIELDS. Unit tests add coverage that HSETEX with repeated FIELDS returns an error.

Written by Cursor Bugbot for commit 470e676. This will update automatically on new commits. Configure here.

@sundb sundb added the release-notes indication that this issue needs to be mentioned in the release notes label Mar 12, 2026
@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Mar 12, 2026

🤖 Augment PR Summary

Summary: This PR makes HSETEX reject requests that specify more than one FIELDS block, preventing later FIELDS sections from silently overriding earlier ones.

Changes: Adds a single-FIELDS validation in the shared hash-field-expire argument parser and extends the unit tests to cover the invalid multi-FIELDS cases.

🤖 Was this summary useful? React with 👍 or 👎

Comment thread src/t_hash.c Outdated
Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

Comment thread src/t_hash.c Outdated
@gentcys gentcys changed the title Raise error for executing HSETEX with multple FIELDS Validate HSETEX does not accept multiple fields Mar 12, 2026
@sundb sundb requested a review from guybe7 March 12, 2026 11:33
Comment thread src/t_hash.c
addReplyError(c, "wrong number of arguments");
return C_ERR;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also make sure that the FIELDS arg was even given (in parseHashCommandArgs and parseHashFieldExpireArgs)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it well.
Do you refer to FIELDS itself or its following arguments numfields field value [field value ...]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you refer to the FIELDS itself. However I wonder it's necessity, because command has arity like 6 for HSETEX, execute command without enough arity would raise the error as below:

127.0.0.1:6379> hsetex myhash FNX EX 100
(error) ERR wrong number of arguments for 'hsetex' command

and we do not allow FNX + FXX, or EX 100 + KEEPTTL at same time, that would raise another error:

127.0.0.1:6379> hsetex myhash FNX EX 100 KEEPTTL
(error) ERR Only one of EX, PX, EXAT, PXAT or KEEPTTL arguments can be specified

another specific case is, FIELDS is not specified, it would raise an error like:

127.0.0.1:6379> hsetex myhash FNX EX 100 1 k v
(error) ERR unknown argument: 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @guybe7 I might understand your point, could you review the latest changes?

@gentcys gentcys requested a review from sundb March 14, 2026 11:40
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Comment thread src/t_hash.c
Copy link
Copy Markdown
Collaborator

@sundb sundb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sundb sundb moved this from Todo to pending in Redis 8.6 Backport Mar 19, 2026
@YaacovHazan YaacovHazan moved this from pending to Todo in Redis 8.6 Backport Mar 19, 2026
@sundb
Copy link
Copy Markdown
Collaborator

sundb commented Mar 19, 2026

@gentcys pls update the top comment, I see the change of needing at least one field was missed.

@gentcys gentcys changed the title Validate HSETEX does not accept multiple fields Improve FIELDS argument validation and error reporting in HSETEX/HGETEX Mar 19, 2026
@gentcys gentcys changed the title Improve FIELDS argument validation and error reporting in HSETEX/HGETEX Fix FIELDS argument validation in HSETEX/HGETEX Mar 19, 2026
@gentcys
Copy link
Copy Markdown
Contributor Author

gentcys commented Mar 19, 2026

@sundb Is the updated title and top comment good by now?

@sundb sundb merged commit 1b615c7 into redis:unstable Mar 19, 2026
18 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Redis 8.8 Mar 19, 2026
@gentcys gentcys deleted the fix/hsetex-multiple-fields branch March 19, 2026 12:26
@YaacovHazan YaacovHazan moved this from Todo to In Progress in Redis 8.6 Backport Mar 19, 2026
YaacovHazan pushed a commit to YaacovHazan/redis that referenced this pull request Mar 19, 2026
Fixes redis#14879 

Improve validation of the FIELDS argument in HSETEX and HGETEX to ensure
exactly one field is provided, rejecting both missing and multiple
fields with consistent and accurate error messages.

Align behavior across both commands.
@sundb sundb mentioned this pull request Mar 23, 2026
YaacovHazan pushed a commit that referenced this pull request Mar 23, 2026
Fixes #14879 

Improve validation of the FIELDS argument in HSETEX and HGETEX to ensure
exactly one field is provided, rejecting both missing and multiple
fields with consistent and accurate error messages.

Align behavior across both commands.
@YaacovHazan YaacovHazan mentioned this pull request Mar 24, 2026
@YaacovHazan YaacovHazan moved this from In Progress to Done in Redis 8.6 Backport Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Issues with HFE commands syntax

4 participants