Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix limit undefined behavior crash in CLUSTER SLOT-STATS #709

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

enjoy-binbin
Copy link
Member

We did not set a default value for limit, but it will be used
in addReplyOrderBy later, the undefined behavior may crash the
server since the value could be negative and crash will happen
in addReplyArrayLen.

An interesting reproducible example (limit reuses the value of -1):

> cluster slot-stats orderby key-count desc limit -1
(error) ERR Limit has to lie in between 1 and 16384 (maximum number of slots).
> cluster slot-stats orderby key-count desc
Error: Server closed the connection

Set the default value of limit to 16384.

We did not set a default value for limit, but it will be used
in addReplyOrderBy later, the undefined behavior may crash the
server since the value could be negative and crash will happen
in addReplyArrayLen.

An interesting reproducible example (limit reuses the value of -1):
```
> cluster slot-stats orderby key-count desc limit -1
(error) ERR Limit has to lie in between 1 and 16384 (maximum number of slots).
> cluster slot-stats orderby key-count desc
Error: Server closed the connection
```

Set the default value of limit to 16384.

Signed-off-by: Binbin <[email protected]>
Signed-off-by: Binbin <[email protected]>
@enjoy-binbin
Copy link
Member Author

The test can be stably reproduced in my local Mac.

@enjoy-binbin enjoy-binbin requested a review from madolson June 28, 2024 05:05
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.09%. Comparing base (1269532) to head (7904bc4).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #709      +/-   ##
============================================
- Coverage     70.23%   70.09%   -0.15%     
============================================
  Files           111      111              
  Lines         60203    60206       +3     
============================================
- Hits          42286    42203      -83     
- Misses        17917    18003      +86     
Files Coverage Δ
src/cluster_slot_stats.c 88.77% <100.00%> (+1.40%) ⬆️

... and 16 files with indirect coverage changes

@madolson madolson merged commit 518f0bf into valkey-io:unstable Jun 28, 2024
19 checks passed
@enjoy-binbin enjoy-binbin deleted the fix_limit_undefined branch June 29, 2024 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants