Repository navigation
Reject wrapped and overflowing --uri database numbers - #761
Merged
Merged
Conversation
parse_uri() read the database number of redis://host:port/N with (int) strtol() and only checked db < 0, so the cast wrapped values outside int: /4294967296 selected db 0, /4294967297 db 1, /6442450943 db 2147483647, and the saturated -99999999999999999999999 became db 0. That is the #725 class #748 fixed for --select-db. The number now goes through parse_unsigned() with an INT_MAX bound, the same rule as --select-db: leading whitespace, one '+' and "-0" are accepted; any other negative, overflow, junk and values above INT_MAX are rejected with the existing "invalid database number '...'" error. An empty path ("redis://host:port/") still selects no database, and #735's userinfo split (including the known '@'-in-path limits pinned by test_config_password_redaction.py) is unchanged. Refs #725 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the comment Review of #761: - Reject list adds -4294967295 and -4294967296, which (int) strtol() wrapped into db 1 and 0, and -18446744073709551615 and -18446744071562067969, which strtoull() without the sign check would negate into db 1 and 2147483647. - The empty-path case now runs with --select-db=3 and checks that "redis://127.0.0.1:1/" keeps it, so resetting it to 0 is caught. - The comment states the rule instead of the history. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira
force-pushed
the
fix/725-uri-db-number
branch
from
October 17, 2026 02:23
35eeb03 to
b5702de
Compare
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.
Follow-up to #748, which left the
--uridatabase number out of scope.Problem
parse_uri()reads the database number inredis://host:port/Nwith(int) strtol()and checks only*endptranddb < 0. Values outsideinttherefore wrap through the cast. On master 7e107ff,--show-configshows:--uripath/4294967296select-db = 0invalid database number '4294967296'/4294967297select-db = 1/6442450943select-db = 2147483647/-99999999999999999999999,/-18446744073709551615,/-18446744071562067969select-db = 0(LONG_MINcast toint)/-4294967295,/-4294967296select-db = 1,0/2147483648,/-1,/abc,/1xRoot cause
The value is narrowed to
intbefore any range check: the same #725 pattern that #748 fixed for--select-db.Fix
The number now goes through
parse_unsigned(db_start, INT_MAX, &db), the same rule as--select-db:+, and-0/-00(read as 0, per Reject wrapped, overflowing and empty values on the remaining numeric options (#725) #748) are accepted.INT_MAXare rejected with Redact the password in --json-out-file and --show-config #735's existing message,error: invalid database number '...'.What is unchanged:
redis://host:port/) still selects no database, so a--select-dbvalue is kept.uri_userinfo_end()) is untouched, including the known '@'-in-path limits pinned bytest_config_password_redaction.py. In particular, a URI with credentials ending in.../1@is still reported asinvalid database number '1@'. Without credentials, the '@' still ends a "userinfo", as pinned by the known-limit test.Tests
New
test_uri_database_numberintests/test_cli_validation_count_flags.py. It runs--uri=redis://127.0.0.1:1/<N> --show-config; parsing happens before the connect to closed port 1.0,7,+3," 5",-0,-00and2147483647, each checked asselect-db = N. With--select-db=3, an empty path keepsselect-db = 3.-1,-2147483648,2147483648,4294967296,4294967297,6442450943, overflow (both signs),-4294967295and-4294967296(which master wraps to db 1 and 0),-18446744073709551615and-18446744071562067969(which astrtoull()parse without the sign check would negate to db 1 and 2147483647),abc,1x,"1 ",+-1,- 1,++1," "and0x10.RLTest
--env oss:test_uri_database_number4294967296,4294967297,6442450943,-4294967295,-4294967296,-18446744073709551615,-18446744071562067969,-99999999999999999999999)test_uri_*tests in tests_oss_simple_flow.pyRelease note:
--uridatabase numbers above 2147483647, or negative values other than-0, are now rejected instead of wrapping to another database.Refs #725
Affected versions
2.2.0 through 2.5.2, and master. The
(int) strtol()parse was added together with--uriin 68fb953 (#311), whose first tag is 2.2.0, and the code is unchanged since. This was reproduced on master 7e107ff. The released versions come from history (git tag --contains) and were not run.🤖 Generated with Claude Code
Note
Low Risk
CLI-only URI parsing change with stricter validation; aligns with existing
--select-dbbehavior and adds tests.Overview
URI database parsing now matches
--select-dbvalidation instead of casting with(int) strtol(), which could silently wrap large values (e.g.4294967297→ db 1).parse_uri()usesparse_unsigned(..., INT_MAX, ...)so leading whitespace,+, and-0/-00still work, while negatives (other than-0), overflow, trailing junk, and values aboveINT_MAXfail witherror: invalid database number '...'. Empty path after/behavior is unchanged.Adds
test_uri_database_numbercovering accepted paths and the rejection cases above via--show-configwithout needing a live Redis.Reviewed by Cursor Bugbot for commit 35eeb03. Bugbot is set up for automated code reviews on this repo. Configure here.