Skip to content

Commit

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

* 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 12, 2024
1 parent 3b3d77f commit 84a331f
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 @@ -325,11 +325,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 @@ -341,7 +341,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 84a331f

Please sign in to comment.