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 - false positive: Potentially uninitialized local variable after noreturn function. #10600

Closed
andyhhp opened this issue Sep 28, 2022 · 8 comments
Labels
acknowledged GitHub staff acknowledges this issue C++ false-positive

Comments

@andyhhp
Copy link

andyhhp commented Sep 28, 2022

I'm transitioning a project from LGTM.com to Github Actions CodeQL.

While doing so, https://github.com/TrenchBoot/secure-kernel-loader/security/code-scanning/18 got reported.

The complaint is a "Potentially uninitialized local variable" and while strictly speaking, this statement is true, the alert is wrong.

In this specific example, all paths leading to this point where the variable isn't suitably initialised end up making a call to reboot() which is __attribute__((noreturn)). In fact, it's a local static function, which also ends with __builtin_unreachable() for extra measure.

Shouldn't these annotations have caused the analysis to realise that the variable is properly initialised?

@jketema
Copy link
Contributor

jketema commented Oct 10, 2022

Apologies for the slow reply. This indeed seems a false positive, and looking at the query I don't expect this false positive to occur. Could you tell me which version of the CodeQL CLI you're using in your workflow? Also the logs produced by CodeQL would useful.

@andyhhp
Copy link
Author

andyhhp commented Oct 12, 2022

It's run "as normal" from a Github action. TrenchBoot/secure-kernel-loader@5a525e7 is the exact workflow file.

Looking through the logs of the run, we've got

Run github/codeql-action/init@v2
Setup CodeQL tools
Load language configuration
Downloading packs

/opt/hostedtoolcache/CodeQL/0.0.0-20220908/x64/codeql/codeql database init --db-cluster /home/runner/work/_temp/codeql_databases --source-root=/home/runner/work/secure-kernel-loader/secure-kernel-loader --language=cpp --begin-tracing --trace-process-name=Runner.Worker.exe
Counting lines of code in /home/runner/work/secure-kernel-loader/secure-kernel-loader
Resolving extractor cpp.
Successfully loaded extractor C/C++ (cpp) from /opt/hostedtoolcache/CodeQL/0.0.0-20220908/x64/codeql/cpp.
Created skeleton CodeQL database at /home/runner/work/_temp/codeql_databases/cpp. This in-progress database is ready to be populated by an extractor.

and

Run github/codeql-action/analyze@v2
/opt/hostedtoolcache/CodeQL/0.0.0-20220908/x64/codeql/codeql version --format=terse
2.10.5
Finalizing cpp
Running queries for cpp
Interpreting results for cpp
Analysis produced the following diagnostic data:

|          Diagnostic          |  Summary   |
+------------------------------+------------+
| Successfully extracted files | 17 results |

Analysis produced the following metric data:

|                         Metric                         | Value |
+--------------------------------------------------------+-------+
| Total lines of C/C++ code in the database              |     0 |
| Total lines of user written C/C++ code in the database |     0 |


/opt/hostedtoolcache/CodeQL/0.0.0-20220908/x64/codeql/codeql database print-baseline /home/runner/work/_temp/codeql_databases/cpp
Counted a baseline of 3402 lines of code for cpp.
Counted a baseline of 3402 lines of code for cpp.

Does this cover what you need?

@jketema
Copy link
Contributor

jketema commented Oct 12, 2022

Does this cover what you need?

Not quite. There's a file called build-tracer.log produced during database creation. This is the file I'm after. Probably the easiest way to get this file is by re-running the scan in debug mode as described here. The file should be part of the database artefact that is created when running in debug mode.

@andyhhp
Copy link
Author

andyhhp commented Oct 12, 2022

@jketema
Copy link
Contributor

jketema commented Oct 13, 2022

Thanks, that does the trick.

This seems to have the same underlying cause as the issue you reported in #10601. In this case this is about NULL not being defined instead of size_t. This means that the nullness check done before the reported line is not properly analysed and CodeQL thinks the unreachable code actually becomes reachable.

@jketema jketema added the acknowledged GitHub staff acknowledges this issue label Oct 13, 2022
@andyhhp
Copy link
Author

andyhhp commented Oct 13, 2022

Ah! We actually have 40 or so issues, and the others were clearly related to size_t, but this one looked as if it was unrelated, hence the separate report. Sorry.

@jketema
Copy link
Contributor

jketema commented Oct 13, 2022

No problem. I can fully understand this wasn't immediately obvious.

@jketema
Copy link
Contributor

jketema commented Oct 14, 2022

Thanks again for reporting this problem. The issue should be fixed in the next version of CodeQL which will be released in a few weeks. Closing this issue for now.

@jketema jketema closed this as completed Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged GitHub staff acknowledges this issue C++ false-positive
Projects
None yet
Development

No branches or pull requests

2 participants