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

nil pointer exception in req() method #25

Closed
MrVine opened this issue Oct 20, 2018 · 3 comments
Closed

nil pointer exception in req() method #25

MrVine opened this issue Oct 20, 2018 · 3 comments

Comments

@MrVine
Copy link
Collaborator

MrVine commented Oct 20, 2018

Software

OS: Windows 10 x64
GO: go1.9.2 windows/amd64
gowebdav: latest version from master

go env

set GOARCH=386
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Go\
set GORACE=
set GOROOT=D:\Programs\Go
set GOTOOLDIR=D:\Programs\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set GO386=sse2
set CC=gcc
set GOGCCFLAGS=-m32 -fmessage-length=0 -fdebug-prefix-map=C:\Users\PC\AppData\Local\Temp\go-build886287271=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=0
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

Issue description

We use http.Do() method inside c.req(), and do not check for errors returned. So, it is possible to receive nil response, and got nil pointer dereference panic in line 42.
http.Do() method will return non-nil error in following cases:

  1. Request is nil
  2. Response missing Location header
  3. Client failed to parse Location header
  4. Method "request.GetBody()" returns error
  5. Http.Client.Send() returns error
  6. Client timeout was exceeded
    In all cases except of (5) this method returns nil as a poiner to http.Response, which will force app to panic later.

Conclusion

Taking into account the above mentioned, we need to perform error-checking for http.Do() method results.

@MrVine MrVine mentioned this issue Oct 20, 2018
@chripo
Copy link
Member

chripo commented Oct 21, 2018

Yes. It got lost.

You are a contributer and you have permission to write/push too. Don't open issues. Use this time an push your fix, even if you're not 100% shure, all things improveable!
Don't be shy. Go on.
Thanks for your report.

@chripo
Copy link
Member

chripo commented Oct 21, 2018

Just try to avoid merge commits. 😀

chripo pushed a commit that referenced this issue Oct 21, 2018
http.Do() method will return non-nil [error] in following cases:
1. Request is nil
2. Response missing Location header
3. Client failed to parse Location header
4. Method "request.GetBody()" returns error
5. Http.Client.Send() returns error
5. Client timeout was exceeded

Signed-off-by: Christoph Polcin <labs@polcin.de>
@chripo chripo closed this as completed Oct 21, 2018
@MrVine
Copy link
Collaborator Author

MrVine commented Oct 21, 2018

@chripo, ok, thanks 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants