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

[release-1.13] Fix possible nil pointer dereference in event-dispatcher #7998

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/kncloudevents/event_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ func (d *Dispatcher) executeRequest(ctx context.Context, target duckv1.Addressab
dispatchInfo.ResponseHeader = response.Header

body := new(bytes.Buffer)
_, readErr := body.ReadFrom(response.Body)
_, err = body.ReadFrom(response.Body)

if isFailure(response.StatusCode) {
// Read response body into dispatchInfo for failures
if readErr != nil && readErr != io.EOF {
if err != nil && err != io.EOF {
dispatchInfo.ResponseBody = []byte(fmt.Sprintf("dispatch resulted in status \"%s\". Could not read response body: error: %s", response.Status, err.Error()))
} else {
dispatchInfo.ResponseBody = body.Bytes()
Expand All @@ -314,7 +314,7 @@ func (d *Dispatcher) executeRequest(ctx context.Context, target duckv1.Addressab
}

var responseMessageBody []byte
if readErr != nil && readErr != io.EOF {
if err != nil && err != io.EOF {
responseMessageBody = []byte(fmt.Sprintf("Failed to read response body: %s", err.Error()))
} else {
responseMessageBody = body.Bytes()
Expand Down
Loading