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

io.ReadCloser io.EOF seems to be should also be whitelisted #66

Open
psydvl opened this issue Jan 25, 2024 · 3 comments
Open

io.ReadCloser io.EOF seems to be should also be whitelisted #66

psydvl opened this issue Jan 25, 2024 · 3 comments

Comments

@psydvl
Copy link
Contributor

psydvl commented Jan 25, 2024

However, this can be solved somehow with the whitelisting that follows interface embedding

Example:

func Magic(rc io.ReadCloser) {
	a := make([]byte, 10)
	_, err := rc.Read(a)
	if err != nil && err != io.EOF {
		fmt.Println(err)
		return
	}
	fmt.Println(a)
}
type MyReader interface{
	io.Reader
}

func MyMagic(rc MyReader) {
	a := make([]byte, 10)
	_, err := rc.Read(a)
	if err != nil && err != io.EOF {
		fmt.Println(err)
		return
	}
	fmt.Println(a)
}

Both raise comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error

@polyfloyd
Copy link
Owner

Thanks for reporting this! I allowed io.EOF from (io.ReadCloser).Read.

The second example is a bit trickier as the allow-list works based on the name of the type. And since MyReader is a custom type it is not known by the allow-list. A solution would involve checking whether the source function implements one of the allowed interfaces, but I have not attempted that yet.

@psydvl
Copy link
Contributor Author

psydvl commented Jan 31, 2024

Should we also expect same behavior for next types?

  • json.Decoder{}.Decode()
  • csv.Reader{}.Read() ReadAll()
  • mime/multipart.Reader{}.NextPart()

https://github.com/search?q=repo%3Agolang%2Fgo+%22func+Example%22+%22%3D%3D+io.EOF%22&type=code

@polyfloyd
Copy link
Owner

Yes, any function in the standard library that returns io.EOF is ok to allow

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

No branches or pull requests

2 participants