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

codeql: init at 2.0.0 #75524

Merged
merged 1 commit into from Dec 31, 2019
Merged

codeql: init at 2.0.0 #75524

merged 1 commit into from Dec 31, 2019

Conversation

jollheef
Copy link
Member

Motivation for this change

Adds codeql ― semantic code analysis engine.

https://securitylab.github.com/tools/codeql

https://semmle.com/codeql

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Lassulus
Copy link
Member

I can't figure out how to use it. I tried this:

[nix-shell:~/src/autowifi]$ codeql database create test --language=python
Initializing database at /home/lass/src/autowifi/test.
Running command [/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/autobuild.sh] in /home/lass/src/autowifi.
[2019-12-23 12:02:33] [build-err] Traceback (most recent call last):
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/index.py", line 15, in <module>
[2019-12-23 12:02:33] [build-err]     import index
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/index.py", line 13, in <module>
[2019-12-23 12:02:33] [build-err]     sys.path = [ zippath ] + sys.path
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/install.py", line 10, in <module>
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/auto_install.py", line 8, in <module>
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/semmle/requirements.py", line 2, in <module>
[2019-12-23 12:02:33] [build-err] ModuleNotFoundError: No module named 'packaging'
[2019-12-23 12:02:33] [ERROR] Spawned process exited abnormally (code 1; tried to run: [/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/autobuild.sh])
A fatal error occurred: Exit status 1 from command [/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/autobuild.sh]

@jollheef
Copy link
Member Author

I can't figure out how to use it. I tried this:

[nix-shell:~/src/autowifi]$ codeql database create test --language=python
Initializing database at /home/lass/src/autowifi/test.
Running command [/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/autobuild.sh] in /home/lass/src/autowifi.
[2019-12-23 12:02:33] [build-err] Traceback (most recent call last):
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/index.py", line 15, in <module>
[2019-12-23 12:02:33] [build-err]     import index
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/index.py", line 13, in <module>
[2019-12-23 12:02:33] [build-err]     sys.path = [ zippath ] + sys.path
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/install.py", line 10, in <module>
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/auto_install.py", line 8, in <module>
[2019-12-23 12:02:33] [build-err]   File "/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/pybuild.zip/semmle/requirements.py", line 2, in <module>
[2019-12-23 12:02:33] [build-err] ModuleNotFoundError: No module named 'packaging'
[2019-12-23 12:02:33] [ERROR] Spawned process exited abnormally (code 1; tried to run: [/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/autobuild.sh])
A fatal error occurred: Exit status 1 from command [/nix/store/ar98b4p2428ihjnxwafkinswxbbc33wv-codeql-2.0.0/codeql/python/tools/autobuild.sh]

Error is related to the build process of your project, not codeql itself.

Here is a minimal example of use for Python:

user@local ~ $ cd $(mktemp -d)                                                                                                                                                      ~
user@local /tmp/tmp.jGgMk8t0AM $ cat > main.py
import os

print("Hello, World!")
user@local /tmp/tmp.jGgMk8t0AM $ codeql database create test --language=python
...
Successfully created database at /tmp/tmp.jGgMk8t0AM/test.
user@local /tmp/tmp.jGgMk8t0AM $ codeql database analyze test --format=csv --output=results.csv ~/src/github.com/Semmle/ql/python/ql/src/Imports/UnusedImport.ql
Running queries.
...
Shutting down query evaluator.
Interpreting results.
user@local /tmp/tmp.jGgMk8t0AM $ cat results.csv
"Unused import","Import is not required as it is not used","recommendation","Import of 'os' is not used.","/main.py","1","1","1","9"

Copy link
Member

@Lassulus Lassulus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested with nix-review

@Lassulus Lassulus merged commit dad53fa into NixOS:master Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants