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

net/url: Panic in (nil).ResolveReference(…) #22229

Closed
wking opened this issue Oct 12, 2017 · 4 comments
Closed

net/url: Panic in (nil).ResolveReference(…) #22229

wking opened this issue Oct 12, 2017 · 4 comments

Comments

@wking
Copy link
Contributor

wking commented Oct 12, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

$ go version
go version go1.7.4 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

This bug is OS-agnostic.

What did you do?

https://play.golang.org/p/grCVrmNOxz

What did you expect to see?

ResolveReference doesn't return an error, so the best we can do is probably return nil if the argument is nil or the argument is relative-enough that we'd need to pull anything off the base object.

What did you see instead?

A panic, but only in cases where the argument is nil, or when the argument is relative-enough that we'd need to pull something of a nil base object.

@ianlancetaylor
Copy link
Contributor

I don't see anything wrong with a panic here. Don't call ResolveReference on a nil URL. That rule is no different than "don't dereference a nil pointer."

@wking
Copy link
Contributor Author

wking commented Oct 12, 2017 via email

@ianlancetaylor
Copy link
Contributor

I don't think we should return nil. For users who are unaware of the change, that simply pushes the breakage elsewhere. Breaking earlier is better than later.

Looking at the code, it seems that ResolveReference will panic exactly when u == nil and ref.IsAbs() is false. So why not test that?

@wking
Copy link
Contributor Author

wking commented Oct 12, 2017

Looking at the code, it seems that ResolveReference will panic exactly when u == nil and ref.IsAbs() is false.

I had to read it over a few times, but yeah, that looks right. Thanks :)

Cross-linking #20924 as a similar issue, but for different methods, in case anyone stumbles across the other while searching.

@wking wking closed this as completed Oct 12, 2017
wking added a commit to wking/casengine that referenced this issue Oct 14, 2017
…base

Avoiding the situation discussed in 4d8f93e (template: Document
unbased ResolveReference panic, 2017-10-12).  In the Go bug I'd filed,
Ian pointed out that (nil).ResolveReference panics if and only if the
reference scheme is nil, and that IsAbs is only looking at the scheme
[1].  So this commit guards against data that would panic
ResolveReference, instead of catching and handling an error/panic that
ResolveReference raises.

I've also added the base URI to the testcase struct, so we can
exercise different values there.  In this case, I needed to use just
the encoded part to get the relative-reference check to raise an error
at all, because some-algorithm:0123456789abcdef matches the URI syntax
with a 'some-algorithm' scheme and '0123456789abcdef' hier-part [2].
That looks (rightly) absolute, so ResolveReference wasn't looking at
the nil base.  By using just the encoded part, we no longer have the
colon required for an absolute URI.

[1]: golang/go#22229 (comment)
[2]: https://tools.ietf.org/html/rfc3986#section-3
[3]: https://tools.ietf.org/html/rfc3986#section-4.2

Signed-off-by: W. Trevor King <wking@tremily.us>
@golang golang locked and limited conversation to collaborators Oct 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants