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

false negative submatch #369

Open
peakle opened this issue Jan 21, 2022 · 1 comment
Open

false negative submatch #369

peakle opened this issue Jan 21, 2022 · 1 comment

Comments

@peakle
Copy link
Contributor

peakle commented Jan 21, 2022

@peakle
Copy link
Contributor Author

peakle commented Jan 21, 2022

test data:

var globalVar *os.File

func negative2() {
	globalVar, _ = ioutil.TempFile("", "") // global var
	kk := globalVar.Name()

	print(kk)
}

rule:

func unclosedResource(m dsl.Matcher) {
	varEscapeFunction := func(x dsl.Var) bool {
		return x.Contains(`$_($*_, $res, $*_)`) || x.Contains(`$_{$*_, $res, $*_}`) ||
			x.Contains(`$_{$*_, $_: $res, $*_}`) || x.Contains(`$_ <- $res`) ||
			x.Contains(`return $*_, $res, $*_`) || x.Contains(`$_[$_] = $res`) ||
			x.Contains(`$_[$res] = $_`)
	}

	m.Match(`$res, $err := $open($*_); $*body`,
		`$res, $err = $open($*_); $*body`,
		`var $res, $err = $open($*_); $*body`,
	).
		Where(m["res"].Type.Implements(`io.Closer`) &&
			m["err"].Type.Implements(`error`) &&
			(!m["body"].Contains(`$res.Close()`) && !varEscapeFunction(m["body"]))).
		Report(`$res.Close() should be deferred right after the $open error check`).
		At(m["res"])
}

debug-group output:

 rejected by m["err"].Type.Implements(`error`)

so as i see if we nulify second var in = assignment , it doesn't have error type in current implemntation

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

1 participant