Skip to content

Nil-pointer panic: mapping can reference repos not in Repositories#743

Open
udf2457 wants to merge 2 commits into
theupdateframework:masterfrom
udf2457:nilpointer
Open

Nil-pointer panic: mapping can reference repos not in Repositories#743
udf2457 wants to merge 2 commits into
theupdateframework:masterfrom
udf2457:nilpointer

Conversation

@udf2457

@udf2457 udf2457 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

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.

for _, repoName := range eachMap.Repositories {
// get target info from that repository
newTargetInfo, err := client.TUFClients[repoName].GetTargetInfo(targetPath)

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>
@udf2457
udf2457 requested a review from a team as a code owner June 19, 2026 10:32
Copilot AI review requested due to automatic review settings June 19, 2026 10:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 NewConfig to ensure every mapping repository name exists in mapFile.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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants