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

Nilaway does not catch panic when using reflect.TypeOf function #190

Open
zsaurabhsabharwal opened this issue Jan 31, 2024 · 2 comments
Open
Labels
enhancement New feature or request false negative

Comments

@zsaurabhsabharwal
Copy link

reflect package states that TypeOf function will return a nil pointer if a nil interface is passed to as an argument (https://cs.opensource.google/go/go/+/refs/tags/go1.21.6:src/reflect/type.go;l=1151)

Screenshot 2024-01-31 at 6 32 00 PM

In the below example, I've passed a nil interface value to this function and tried to call a pointer method on it, when executing the script I get a panic with nil pointer dereference error message, however nilaway fails to detect this.

Screenshot 2024-01-31 at 6 28 38 PM

@sonalmahajan15
Copy link
Contributor

@zsaurabhsabharwal , thanks for reporting! We'll look into adding support for this in NilAway. Contributions are welcome, of course. :)

@sonalmahajan15 sonalmahajan15 added enhancement New feature or request false negative labels Feb 2, 2024
@yuxincs
Copy link
Contributor

yuxincs commented Feb 16, 2024

FWIW, for this particular case (and possibly other similar cases from stdlib), we can probably model it in NilAway (basically treating the return value as nilable without analyzing the body). The reason is that it uses functions from runtime (i.e., unsafe here) that NilAway simply cannot analyze, even if told to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request false negative
Projects
None yet
Development

No branches or pull requests

3 participants