Skip to content

Commit 990cdb8

Browse files
authored
fix: multirepo potential nil pointer dereference (#658)
potential nil pointer dereference Signed-off-by: mrdan4es <mrdan4es@gmail.com>
1 parent 40cd269 commit 990cdb8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

metadata/multirepo/multirepo.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,13 @@ func (client *MultiRepoClient) DownloadTarget(repos []string, targetFile *metada
311311
log := metadata.GetLogger()
312312

313313
for _, repoName := range repos {
314+
repoClient, ok := client.TUFClients[repoName]
315+
if !ok {
316+
return "", nil, fmt.Errorf("no client found for repo %q", repoName)
317+
}
318+
314319
// see if the target is already present locally
315-
targetPath, targetBytes, err := client.TUFClients[repoName].FindCachedTarget(targetFile, filePath)
320+
targetPath, targetBytes, err := repoClient.FindCachedTarget(targetFile, filePath)
316321
if err != nil {
317322
return "", nil, err
318323
}
@@ -322,7 +327,7 @@ func (client *MultiRepoClient) DownloadTarget(repos []string, targetFile *metada
322327
return targetPath, targetBytes, nil
323328
}
324329
// not present locally, so let's try to download it
325-
targetPath, targetBytes, err = client.TUFClients[repoName].DownloadTarget(targetFile, filePath, targetBaseURL)
330+
targetPath, targetBytes, err = repoClient.DownloadTarget(targetFile, filePath, targetBaseURL)
326331
if err != nil {
327332
// TODO: decide if we should error if one repository serves the expected target info, but we fail to download the actual target
328333
// try downloading the target from the next available repository

0 commit comments

Comments
 (0)