Nil-pointer panic: mapping can reference repos not in Repositories#743
Open
udf2457 wants to merge 2 commits into
Open
Nil-pointer panic: mapping can reference repos not in Repositories#743udf2457 wants to merge 2 commits into
udf2457 wants to merge 2 commits into
Conversation
A malformed or adversarially crafted map file could trigger a nil-pointer dereference. If a mapping entry references a repo name that isn't in the `Repositories` map, `client.TUFClients[repoName]` returns `nil`, and the `.GetTargetInfo()` call would panic. Signed-off-by: udf2457 <udf2457@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens multi-repo map parsing by rejecting map files whose mapping[].repositories entries reference repository names that are not present in the top-level repositories section, preventing a nil-pointer dereference later when resolving targets.
Changes:
- Add a validation pass in
NewConfigto ensure every mapping repository name exists inmapFile.Repositories. - Return a clear error when the map file references an unknown repository.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+105
to
+112
| // validation pass against malformed or adversarially crafted map | ||
| for _, m := range mapFile.Mapping { | ||
| for _, repo := range m.Repositories { | ||
| if _, ok := mapFile.Repositories[repo]; !ok { | ||
| return nil, fmt.Errorf("mapping references unknown repository %q", repo) | ||
| } | ||
| } | ||
| } |
Comment on lines
+105
to
+112
| // validation pass against malformed or adversarially crafted map | ||
| for _, m := range mapFile.Mapping { | ||
| for _, repo := range m.Repositories { | ||
| if _, ok := mapFile.Repositories[repo]; !ok { | ||
| return nil, fmt.Errorf("mapping references unknown repository %q", repo) | ||
| } | ||
| } | ||
| } |
Add validation for null mappings in mapFile. Signed-off-by: udf2457 <udf2457@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.
A malformed or adversarially crafted map file could trigger a nil-pointer dereference.
If a mapping entry references a repo name that isn't in the
Repositoriesmap,client.TUFClients[repoName]returnsnil, and the.GetTargetInfo()call would panic.go-tuf/metadata/multirepo/multirepo.go
Lines 257 to 259 in 4b704cd