Repository navigation
Out of Bounds read in valkey-benchmark - #4142
enjoy-binbin merged 1 commit into
Conversation
The arbitrary command sequence parser uses ';' to separate commands and iterates until i == argc. If a repeat count is provided without a following command, start becomes equal to argc. During the sentinel iteration, the parser evaluates sds_args[i][0] before checking i == argc, resulting in an out-of-bounds read and undefined behaviour. Guard the repeat-count parsing by checking i < argc before accessing sds_args[i]. Signed-off-by: lightsigma96 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe benchmark command parser adds an ChangesBenchmark command parsing
Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #4142 +/- ##
============================================
+ Coverage 76.58% 76.69% +0.11%
============================================
Files 162 162
Lines 81253 81253
============================================
+ Hits 62226 62321 +95
+ Misses 19027 18932 -95
🚀 New features to boost your workflow:
|
Running: ```sh ./valkey-benchmark -t get 10000 ``` causes `valkey-benchmark` to segfault. After option parsing, the remaining argument (`10000`) is interpreted as a repeat count for an arbitrary command sequence. Since no command follows the repeat count, `start` becomes equal to `argc`. When `start` becomes equal to `argc`, the parser evaluates `sds_args[i][0]` before checking that `i` is still within bounds, resulting in an out-of-bounds read and undefined behaviour. This change guards the repeat-count parsing by checking `i < argc` before accessing `sds_args[i]`. Note: This avoids reading out of bounds but still does not handle what happens after that. Signed-off-by: lightsigma96 <[email protected]> Signed-off-by: Alon Arenberg <[email protected]>
Running: ```sh ./valkey-benchmark -t get 10000 ``` causes `valkey-benchmark` to segfault. After option parsing, the remaining argument (`10000`) is interpreted as a repeat count for an arbitrary command sequence. Since no command follows the repeat count, `start` becomes equal to `argc`. When `start` becomes equal to `argc`, the parser evaluates `sds_args[i][0]` before checking that `i` is still within bounds, resulting in an out-of-bounds read and undefined behaviour. This change guards the repeat-count parsing by checking `i < argc` before accessing `sds_args[i]`. Note: This avoids reading out of bounds but still does not handle what happens after that. Signed-off-by: lightsigma96 <[email protected]> Signed-off-by: Alon Arenberg <[email protected]>
Description
Running:
causes
valkey-benchmarkto segfault.After option parsing, the remaining argument (
10000) is interpreted as a repeat count for an arbitrary command sequence. Since no command follows the repeat count,startbecomes equal toargc.When
startbecomes equal toargc, the parser evaluatessds_args[i][0]before checking thatiis still within bounds, resulting in an out-of-bounds read and undefined behaviour.This change guards the repeat-count parsing by checking
i < argcbefore accessingsds_args[i].Expected Behaviour
The benchmark should reject the malformed input instead of crashing.
How to Reproduce
or
Testing
make test.Further