Skip to content

false positive with a Body being replaced by a NopCloser #76

Description

@ccoVeille

Please consider the following code

package a

import (
	"bytes"
	"io"
	"net/http"
)

func readNoOp(url string) (*http.Response, error) {
	r, err := http.DefaultClient.Get(url)
	if err != nil {
		return r, err
	}

	raw, err := io.ReadAll(r.Body)
	if err != nil {
		return r, err
	}
	r.Body.Close()

	r.Body = io.NopCloser(bytes.NewReader(raw))

	return r, nil
}

func issuenop(url string) error {
	r, err := readNoOp(url) # body close will report an issue here
	if err != nil {
		return err
	}

	_ = r
	return nil
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions