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/http: Request.WithContext now panics if URL is nil #20601

Closed
rhysh opened this issue Jun 7, 2017 · 3 comments
Closed

net/http: Request.WithContext now panics if URL is nil #20601

rhysh opened this issue Jun 7, 2017 · 3 comments
Milestone

Comments

@rhysh
Copy link
Contributor

rhysh commented Jun 7, 2017

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

$ go1.7 version
go version go1.7.6 darwin/amd64
$ go1.8 version
go version go1.8.3 darwin/amd64
$ go-tip version
go version devel +4e7067cde4 Wed Jun 7 02:13:51 2017 +0000 darwin/amd64

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

$ go-tip env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/rhys/go"
GORACE=""
GOROOT="/Users/rhys/go/version/go-tip"
GOTOOLDIR="/Users/rhys/go/version/go-tip/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/49/zmds5zsn75z1283vtzxyfr5hj7yjq4/T/go-build294697682=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

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

$ cat ./withcontext.go
package main

import (
	"context"
	"net/http"
)

func main() {
	r := &http.Request{}
	r.WithContext(context.Background())
}

What did you expect to see?

$ go1.7 run -gcflags="-trimpath=$PWD" ./withcontext.go ; echo $?
0
$ go1.8 run -gcflags="-trimpath=$PWD" ./withcontext.go ; echo $?
0

net/http.Request.WithContext does not document that the URL field must be non-nil, and both Go 1.7 and 1.8 allow WithContext to be called with a nil URL field.

What did you see instead?

$ go-tip run -gcflags="-trimpath=$PWD" ./withcontext.go ; echo $?
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11be3c5]

goroutine 1 [running]:
net/http.(*Request).WithContext(0xc420053e78, 0x13725c0, 0xc4200140a0, 0x3e7)
	/usr/local/go/src/net/http/request.go:337 +0xc5
main.main()
	withcontext.go:10 +0x7c
exit status 2
1
@bradfitz bradfitz self-assigned this Jun 7, 2017
@bradfitz bradfitz added this to the Go1.9 milestone Jun 7, 2017
@gopherbot
Copy link

CL https://golang.org/cl/45073 mentions this issue.

@bradfitz
Copy link
Contributor

bradfitz commented Jun 7, 2017

Thanks. Regression from the #20068 fix.

/cc @odeke-em

@odeke-em
Copy link
Member

odeke-em commented Jun 7, 2017

Thanks for the report @rhysh and for the fix @bradfitz, I hadn't seen this, was on a flight back home.

@golang golang locked and limited conversation to collaborators Jun 7, 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

4 participants