Skip to content

Fix SET mutually exclusive NX/XX and IF* options - #15291

Merged
sundb merged 3 commits into
redis:unstablefrom
mehmettokgoz:set-cond_mut_excl-fix
Jul 2, 2026
Merged

sundb merged 3 commits into
redis:unstablefrom
mehmettokgoz:set-cond_mut_excl-fix

Conversation

@mehmettokgoz

@mehmettokgoz mehmettokgoz commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Follow #14435

The conditions NX, XX, IFEQ, IFNE, IFDEQ and IFDNE belong to a single mutually-exclusive group. The IF* parse branches enforced this against the whole group (cond_mut_excl), but the NX/XX branches only checked each other.

This made rejection depend on argument order. SET k v NX IFEQ x was rejected (the IFEQ branch saw NX already set), but SET k v IFEQ x NX was accepted (the NX branch ignored the IFEQ flag).

Affected command examples (all silently accepted before the fix):

  • SET k v IFEQ hello NX
  • SET k v IFEQ hello XX
  • SET k v IFNE world NX
  • SET k v IFDEQ 0123456789abcdef NX

Note

Low Risk
Small change to SET argument parsing only; it rejects previously accepted invalid syntax and does not alter successful SET semantics.

Overview
SET extended-option parsing now treats NX, XX, and the IFEQ / IFNE / IFDEQ / IFDNE conditions as one mutually exclusive group during argument parsing.

Previously, the IF* branches used the full cond_mut_excl mask, but NX and XX only blocked each other. That made validation depend on token order—for example SET k v NX IFEQ x failed while SET k v IFEQ x NX was accepted. The NX and XX branches in parseExtendedStringArgumentsOrReply now use the same (cond_mut_excl & ~OBJ_SET_NX) / (cond_mut_excl & ~OBJ_SET_XX) checks as the IF* options, so invalid combinations always return a syntax error regardless of order.

Unit tests were added for NX/XX paired with each IF* flag (both orderings) and for IF* flags combined with each other, asserting the key is unchanged on error.

Reviewed by Cursor Bugbot for commit 833bc97. Bugbot is set up for automated code reviews on this repo. Configure here.

@jit-ci

jit-ci Bot commented Jun 1, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@CLAassistant

CLAassistant commented Jun 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

This change touches performance-sensitive code paths. Adding the action:run-benchmark label will trigger the CE Performance suite so we can see the impact before merge.

@sundb

sundb commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

My concern is that this might be a breaking change.

@sundb
sundb requested a review from minchopaskal June 2, 2026 01:24
@minchopaskal

minchopaskal commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

but the NX/XX branches only checked each other.

Do note that after the parsing stage in setGenericCommand we have:

if ((flags & OBJ_SET_NX && found) ||
    (flags & (OBJ_SET_XX | OBJ_SET_IFEQ | OBJ_SET_IFDEQ) && !found))
{
    if (!(flags & OBJ_SET_GET)) {
        addReply(c, abort_reply ? abort_reply : shared.null[c->resp]);
    }
    return;
}

Affected command examples (all silently accepted before the fix):
SET k v IFEQ hello NX

Here is output of redis-cli:

$ ./src/redis-cli
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> set k hello
OK
127.0.0.1:6379> set k v ifeq hello nx
(nil)
127.0.0.1:6379> get k
"hello"

Can you clarify WDYM by silently accepted ?

EDIT: my bad. I see the other way around is indeed syntax error.
@sundb We have two approaches here

  • accept the change which indeed is breaking (although I don't think in practice anyone uses the command with both if* and NX/XX at the same time).
  • accept the oversight and leave it like this. The current behavior is still correct (i.e set key <new-val> ifeq <current-value> nx is still rejected but not as a syntax error. Same goes for the other examples.)

@LiorKogan

LiorKogan commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

I'd suggest accepting this change.
Since the new behavior aligns with the documentation, this is a fix (stricter syntax checks) rather than a breaking change.

@minchopaskal minchopaskal left a comment

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.

LGTM

@minchopaskal minchopaskal added the action:run-benchmark Triggers the benchmark suite for this Pull Request label Jun 2, 2026
@fcostaoliveira

Copy link
Copy Markdown
Collaborator

CE Performance Automation : step 1 of 2 (build) STARTING...

This comment was automatically generated given a benchmark was triggered.
Started building at 2026-06-02 09:42:17.158838
You can check each build/benchmark progress in grafana:

  • git hash: 971600d
  • git branch: mehmettokgoz:set-cond_mut_excl-fix
  • commit date and time: n/a
  • commit summary: n/a
  • test filters:
    • command priority lower limit: 0
    • command priority upper limit: 10000
    • test name regex: .*
    • command group regex: .*

@fcostaoliveira

fcostaoliveira commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

CE Performance Automation : step 2 of 2 (benchmark) RUNNING...

This comment was automatically generated given a benchmark was triggered.

Started benchmark suite at 2026-06-17 15:01:52.272529 and took 158.071071 seconds up until now.
Status: [#-------------------------------------------------------------------------------] 0.71% completed.

In total will run 140 benchmarks.
- 139 pending.
- 1 completed:
- 1 successful.
- 0 failed.
You can check a the status in detail via the grafana link

@sundb sundb added release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository labels Jun 2, 2026
Comment thread tests/unit/type/string.tcl Resolved
@sundb

sundb commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Just realize that 914eac4 is wrong. If we want to cover this bug, we need to put the IF* argument before NX/XX. Revert it.

@sundb
sundb merged commit 2c9c04c into redis:unstable Jul 2, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Redis 8.10 Jul 2, 2026
@ShooterIT ShooterIT moved this from Todo to In Progress in Redis 8.4 Backport Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action:run-benchmark Triggers the benchmark suite for this Pull Request release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository

Projects

Status: Done
Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants