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

CreateEventWithHTTPClient nil pointer dereference #274

Closed
blockpane opened this issue Feb 18, 2021 · 4 comments · Fixed by #278
Closed

CreateEventWithHTTPClient nil pointer dereference #274

blockpane opened this issue Feb 18, 2021 · 4 comments · Fixed by #278
Milestone

Comments

@blockpane
Copy link
Contributor

Line 52 of event.go

has the following:

	resp, err := client.Do(req)
	if err != nil {
		return &EventResponse{HttpStatus: resp.StatusCode}, err
	}

In the case of an actual error, it is very likely that resp is nil, and will result in a runtime panic. For example:

standby_1  | panic: runtime error: invalid memory address or nil pointer dereference
standby_1  | [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x673028]
standby_1  |
standby_1  | goroutine 1 [running]:
standby_1  | github.com/PagerDuty/go-pagerduty.CreateEventWithHTTPClient(0x7ffe1cd47f17, 0x20, 0x7b3de3, 0x7, 0x7ffe1cd47eed, 0xc, 0xc0004d6340, 0x34, 0x0, 0x0, ...)
standby_1  | 	/Users/tag/pkg/mod/github.com/!pager!duty/go-pagerduty@v1.3.0/event.go:52 +0x588
standby_1  | github.com/PagerDuty/go-pagerduty.CreateEvent(...)
standby_1  | 	/Users/tag/pkg/mod/github.com/!pager!duty/go-pagerduty@v1.3.0/event.go:36
standby_1  | main.notifyPagerduty(0xc0004bfa00, 0x7bdff3, 0x20, 0x7ffe1cd47eed, 0xc, 0x7ffe1cd47f17, 0x20, 0x0, 0x0)

The V2 client handles this properly and returns nil. (Also note: I meant to use the V2 API in the first place, so this doesn't actually affect me.)

Thanks for the handy library.

@theckman
Copy link
Collaborator

theckman commented Feb 20, 2021

@blockpane good lookin' out. Would you be able to raise a PR? If not I can get to it this weekend.

If you raise the PR I can review it + merge it; otherwise I'm blocked on a PagerDuty employee giving me a review since I don't have the power to merge my own PRs.

In short, I think making this a wrapped error (fmt.Errorf("failed to action request: %w", err)) would be the right fix.

@blockpane
Copy link
Contributor Author

Absolutely, but I don't see a develop branch, where should I send the PR? master?

@blockpane
Copy link
Contributor Author

Assuming you take Friday nights off, like I should, lol, I assumed a PR vs master, if inappropriate we can revisit next week, cheers, and thanks again for providing a useful free library :)

@theckman
Copy link
Collaborator

theckman commented Mar 7, 2021

This will be included in v1.4.0 when it's eventually release. If you're actively running into this on v1.3.0, please file an issue and we can work on backporting the fix to a v1.3.1.

@theckman theckman changed the title CreateEventWithHTTPClient nil pointer reference CreateEventWithHTTPClient nil pointer dereference Apr 22, 2021
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

Successfully merging a pull request may close this issue.

2 participants