Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httputil: work around NPE in signer.Add() #1999

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

glebsts
Copy link

@glebsts glebsts commented Mar 5, 2024

If auth section is empty in config file, instance of Signer 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, method Add 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 of signer receiver no matter what. But if auth section was missing in config, use has default value of nil and produces assignment 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 over nil map is ok).

There is no test file for signer, so I did not create a new test case I added one

@glebsts glebsts requested a review from a team as a code owner March 5, 2024 08:38
@glebsts glebsts requested review from crozzy and removed request for a team March 5, 2024 08:38
@app-sre-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@glebsts glebsts changed the title work around NPE in signer.Add() httputil: work around NPE in signer.Add() Mar 6, 2024
Copy link
Member

@hdonnay hdonnay left a comment

Choose a reason for hiding this comment

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

Ah, good catch.

I'd prefer if the conditional were the other way, to keep it consistent with the other checks in that function. With that change, LGTM

@glebsts
Copy link
Author

glebsts commented Mar 7, 2024

@hdonnay Hello, could you please clarify about "conditionals being other way"?
Do you mean smth like

if s.use == nil {
  return errors.New("authority map not initialized, perhaps missing auth section in config")
}

?

@glebsts glebsts requested a review from hdonnay March 18, 2024 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants