httputil: work around NPE in signer.Add() #1999
Open
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.
If
auth
section is empty in config file, instance ofSigner
is initialized with default field values:https://github.com/quay/clair/blob/v4.7.3/internal/httputil/signer.go#L29
Later e.g. in
report
command processing if configuration is used, methodAdd
is used as "marks the authority in uri as one that expects signed requests":https://github.com/quay/clair/blob/v4.7.3/cmd/clairctl/report.go#L145
In this method an entry is being added to
use
field ofsigner
receiver no matter what. But ifauth
section was missing in config,use
has default value of nil and producesassignment to entry in nil map
.This patch fixes internal logic, but I decided to keep URI parsing before actually checking for nil to give faster feedback to user if uri is e.g. malformed. Feel free to suggest change in such a flow.
Method
Add
is called from multiple commands, so I changed it inside the method, not pre-checking the calls.Other
Signer
fields seem to be safe (ranging overnil
map is ok).There is no test file for signer,
so I did not create a new test caseI added one