Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix potential panics #3395

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix potential panics #3395

wants to merge 1 commit into from

Conversation

kayrus
Copy link
Contributor

@kayrus kayrus commented May 23, 2025

Fixes potential panic, when BuildQueryString returns nil url.

@kayrus kayrus added the backport-v2 This PR will be backported to v2 label May 23, 2025
@github-actions github-actions bot added semver:patch No API change edit:networking This PR updates networking code edit:orchestration This PR updates orchestration code edit:loadbalancer This PR updates loadbalancer code edit:objectstorage This PR updates objectstorage code edit:gophercloud This PR updates common Gophercloud code labels May 23, 2025
@coveralls
Copy link

Coverage Status

coverage: 63.865% (+0.04%) from 63.83%
when pulling 9027675 on kayrus:fix-panic
into ad0459b on gophercloud:main.

@pierreprinetti
Copy link
Member

At first sight, this looks like a no-no. What panic is this fixing?

@kayrus
Copy link
Contributor Author

kayrus commented May 23, 2025

I standardized the ListOpts interfaces to follow a consistent pattern. During this process, I noticed that BuildQueryString can return a nil URL. While I can't envision a realistic scenario where q.String() would panic, this change is primarily cosmetic.

@stephenfin
Copy link
Contributor

Wait, I missed @pierreprinetti's comment and can't remove my approval. Please let's ensure Pierre's happy before we merge this, if possible.

@@ -438,7 +438,7 @@ func BuildQueryString(opts any) (*url.URL, error) {
return &url.URL{RawQuery: params.Encode()}, nil
}
// Return an error if the underlying type of 'opts' isn't a struct.
return nil, fmt.Errorf("Options type is not a struct.")
return &url.URL{}, fmt.Errorf("Options type is not a struct.")
Copy link
Member

Choose a reason for hiding this comment

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

It is surprising to see an object being built while returning an error. I think it is perfectly valid to return nil alongside a non-nil error.

@pierreprinetti
Copy link
Member

I standardized the ListOpts interfaces to follow a consistent pattern.

I'd rather change the other functions to gracefully handle BuildQueryString returning a nil alonside a non-nil error.

@kayrus
Copy link
Contributor Author

kayrus commented May 23, 2025

I'd rather change the other functions to gracefully handle BuildQueryString returning a nil alonside a non-nil error.

this was my first attempt, but I thought it will be better to cover this in core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v2 This PR will be backported to v2 edit:gophercloud This PR updates common Gophercloud code edit:loadbalancer This PR updates loadbalancer code edit:networking This PR updates networking code edit:objectstorage This PR updates objectstorage code edit:orchestration This PR updates orchestration code semver:patch No API change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants