microsoft / infersharp

Infer# is an interprocedural and scalable static code analyzer for C#. Via the capabilities of Facebook's Infer, this tool detects null dereferences, resource leaks, and thread-safety violations. It also performs taint flow tracking to detect critical security vulnerabilities like SQL injections.
MIT License
727 stars 28 forks source link

VS 2022 Extension - There was nothing to analyze #192

Closed LouHendricks closed 1 year ago

LouHendricks commented 1 year ago

Hello, I wanted to try out Infer# after watching the session presented at DotNetConf. I installed the extension in VS2022 and let it do the setup (I already had WSL installed). I then tried to let it analyze a small console app I've been working on. Every time I run the analysis I get the same results:

Copying binaries to a staging folder...

Code translation started... Translation stage 1/3: Loading binaries. Translation stage 2/3: Computing type environment. Translation stage 3/3: Computing control-flow graph.

Coverage Statistics:

Method successfully translated: 12851 (85%) Method partially translated: 2351 (15%) Instructions translated: 305482 (65%) Instructions skipped: 161653 (35%)

Code translation completed. Analyzing...

Capturing using JSON mode... Methods analyzed: 0 Nothing to compile. Try cleaning the build first. There was nothing to analyze.

No issues found

I have tried running it against the root folder of my project, the bin folder and the debug folder but it always haves the same. I have not been able to find any troubleshooting steps that mention a situation like this. Thanks in advance for any assistance you can provide.

xinshiMSFT commented 1 year ago

This is quite strange. The coverage stats show that the binaries you want to analyze are being properly translated, but somehow fail the core analysis. Changing the path won't help because we iterate through the directory you specified in .infersharpconfig and copy only the .dll and .pdb files to WSL for analysis.

Can you share a screenshot of what's in the /infersharp/infer-staging folder in your infersharp1.4 WSL distro? There should be 3 files cfg.json, cfg.txt and tenv.json alongside with your binaries.

LouHendricks commented 1 year ago

infersharp

Requested file is attached.

xinshiMSFT commented 1 year ago

Thank you! Can you please do the following and share the output logs?

  1. Copy IMHCTools.dll and IMHCTools.pdb to a different folder, say /infersharp/IMHCTools
  2. cd to /infersharp and manually trigger the analysis by running ./run_infersharp.sh IMHCTools
LouHendricks commented 1 year ago

I'm not sure what's going but perhaps it's the reason I'm having an issue. I can navigate the infersharp folders in Windows file explorer but when I go into WSL it won't let me into the rootfs folder so I can't get into the folder where I need to try running the script. Did infersharp set folder permissions during install?

root@CTC-CORP-LOUIS:/mnt/c/Users/louis.hendricks# cd infersharp1.4/ root@CTC-CORP-LOUIS:/mnt/c/Users/louis.hendricks/infersharp1.4# ls -l total 0 -rwxrwxrwx 1 root root 0 Nov 10 13:42 fsserver d--------- 1 root root 512 Nov 10 11:02 rootfs drwxrwxrwx 1 root root 512 Nov 10 13:42 temp root@CTC-CORP-LOUIS:/mnt/c/Users/louis.hendricks/infersharp1.4# root@CTC-CORP-LOUIS:/mnt/c/Users/louis.hendricks/infersharp1.4# cd rootfs -bash: cd: rootfs: Permission denied root@CTC-CORP-LOUIS:/mnt/c/Users/louis.hendricks/infersharp1.4#

xinshiMSFT commented 1 year ago

I don't think we set folder permission explicitly during install.

This is on my devbox: image

The structure looks a bit different from yours as I don't have rootfs.

Regardless, can you try moving IMHCToolsV2.dll and IMHCToolsV2.pdb to a separate folder on Windows and edit .infersharpconfig to point to that folder and run via VS extension?

LouHendricks commented 1 year ago

image

I figured out what you initially had asked me to do. I got the dll and pdf into their own folder and ran the script against them from WSL. Similar results as running from VS extension.

xinshiMSFT commented 1 year ago

Thanks! How did you build your project and what is the .NET version you are targeting? Also, do you think it would be possible to share the two binary files with us?

LouHendricks commented 1 year ago

image Everything is .Net 6 and I'm just using Build Solution from the Visual Studio menus to build. That project has some customer code in it but I'm uploading binaries for another project as every project I have tried so far has given me the "nothing to analyze" message. infer-staging.zip

xinshiMSFT commented 1 year ago

Looks like a setup/env issue to me. I was able to analyze your binaries: image

Can you try reinstalling the WSL distro:

  1. Unregister the distro - wsl --unregister infersharp1.4.
  2. Go to VS and click on Tools -> Infer# Analysis to install the distro and try again?
LouHendricks commented 1 year ago

I have it working now. Unregistering and reinstalling the distro did not fix it.

Our organization moved everyone to a new domain not too long ago so I decided to reinstall everything and that got it working. I uninstalled WSL and the Linux Kernel update, rebooted, installed WSL, rebooted, installed the WSL X64 kernel update, set default version to 2 and installed Ubuntu 20.04 distro to test.

Everything looked good so I launched the VS Extension again. It installed the distro again and this time when I ran the analysis it worked. I still don't know what could have been "off" in my workstation configuration but thank you for taking the time to work through it with me.