fix: reject bare "(" and empty string as score in ZRANGEBYSCORE#3493
Open
Yanhu007 wants to merge 1 commit intovalkey-io:unstablefrom
Open
fix: reject bare "(" and empty string as score in ZRANGEBYSCORE#3493Yanhu007 wants to merge 1 commit intovalkey-io:unstablefrom
Yanhu007 wants to merge 1 commit intovalkey-io:unstablefrom
Conversation
When ZRANGEBYSCORE receives a bare "(" (length 1), the parser calls
valkey_strtod_n with zero length, which returns 0.0 and sets eptr
to the null terminator. The existing check passes, so "(" is
silently treated as "(0.0" (exclusive zero).
Similarly, an empty string "" is accepted and parsed as 0.0.
Add length checks:
- Bare "(" (len < 2): return C_ERR immediately
- Empty string (len == 0): return C_ERR immediately
Both min and max parsing paths are fixed.
This was flagged as Coverity CID 901320 (Out-of-bounds access).
Fixes valkey-io#3483
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3493 +/- ##
============================================
+ Coverage 76.53% 76.79% +0.25%
============================================
Files 157 157
Lines 79045 79052 +7
============================================
+ Hits 60501 60709 +208
+ Misses 18544 18343 -201
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3483
Problem
ZRANGEBYSCORE(andZCOUNT,ZRANGESTORE, etc.) accepts a bare(as a valid score, silently parsing it as(0.0(exclusive zero). An empty string""is also accepted as0.0.Root cause: when
s = "("(length 1),valkey_strtod_n(s + 1, 0, &eptr)is called with zero length. The parser returns 0.0 and setseptrto the null terminator. Theeptr[0] != 0check passes.This was flagged as Coverity CID 901320 (Out-of-bounds access, High impact).
Fix
Add length guards in
zslParseRange():len < 2after detecting(prefix →C_ERR(bare paren, no number)len == 0for non-prefixed strings →C_ERR(empty string)Applied to both min and max parsing paths.
Before / After