Repository navigation
Reject malformed and negative indexes in tree paths instead of panicking - #2345
Open
Saadanjum0 wants to merge 1 commit into
Open
Saadanjum0 wants to merge 1 commit into
Saadanjum0 wants to merge 1 commit into
Conversation
parseTreePath, which handles the path argument of --extract, set and unset, panicked for an empty component ([]), a lone quote (["]) and negative indexes ([-1]). Return an error for these instead. Signed-off-by: Saadanjum0 <160885369+Saadanjum0@users.noreply.github.com>
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.
Problem
The path argument of
--extract,sops setandsops unsetcrashes sops with a Go panic for some malformed inputs instead of reporting an error:Cause
parseTreePathincmd/sops/main.goindexescomponent[0]and slicescomponent[1:len-1]without checking the component is long enough, and accepts negative numbers, which the tree code insops.gothen uses directly as a slice index (the bounds checks there only look at the upper bound).Fix
parseTreePathis the single place all of these commands parse paths, so it now returns an error for an empty component, a one-character quoted component, and a negative index.Testing
TestParseTreePathandTestParseTreePathInvalidincmd/sops/main_test.go. The invalid-path test panics onmainwithout the change and passes with it.go test ./...: everything passes excepthcvaultandkms(need Docker, not available here) andpgp(TestPGP, no GnuPG test key in the keyring here). Those three are unrelated to this change.Related: #2344 also changes index handling (in
sops.go, notparseTreePath). It would turn a negative index into an out-of-range error, but does not cover[]or["]. The two changes do not conflict.