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

G104 fails to catch err reassignments #891

Open
omercnet opened this issue Nov 13, 2022 · 2 comments
Open

G104 fails to catch err reassignments #891

omercnet opened this issue Nov 13, 2022 · 2 comments

Comments

@omercnet
Copy link

Summary

Since err is commonly used, it's not uncommon to have it reassigned
If someone forgets to check it before reassigning it, G104 should catch it

Steps to reproduce the behavior

package main

import (
	"io"
	"log"
	"os"
)

func main() {
	_, _ = io.WriteString(os.Stdout, "Hello World") // # this is ok

	_, err := io.WriteString(os.Stdout, "Hello World")
	if err != nil { // good
		log.Fatal(err)
	}

	_, err = io.WriteString(os.Stdout, "Hello World") // # this err will not be checked
	_, err = io.WriteString(os.Stdout, "Hello World") // # this err will be checked

	if err != nil { // checking the second err but not the first one
		log.Fatal(err)
	}

}

gosec version

2.14.0

Go version (output of 'go version')

go version go1.19.2

Operating system / Environment

darwin/arm64

Expected behavior

Should catch the err that wasn't checked

Actual behavior

Doesn't.

@omercnet
Copy link
Author

https://staticcheck.io/ does catch this, worth looking into how they implement this check

@TimonOmsk
Copy link
Contributor

@ccojocar I'll take this one. Finally have some time to dive deep into the SSA :)

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

No branches or pull requests

3 participants