Skip to content

Commit

Permalink
[release-1.13] Fix possible nil pointer dereference in event-dispatch…
Browse files Browse the repository at this point in the history
…er (#7998)

* Fix possible nil pointer dereference in event-dispatcher

* readErr -> err

---------

Co-authored-by: Christoph Stäbler <[email protected]>
  • Loading branch information
knative-prow-robot and creydr authored Jun 13, 2024
1 parent 0673f36 commit 1c51d9a
Showing 1 changed file with 3 additions and 3 deletions.
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

0 comments on commit 1c51d9a

Please sign in to comment.