Merge branch 'main' into path-sensitive-stack-variable-reachability-analysis

This commit is contained in:
Mathias Vorreiter Pedersen
2021-07-12 14:46:44 +02:00
2217 changed files with 205623 additions and 29266 deletions

View File

@@ -0,0 +1,97 @@
name: Check framework coverage changes
on:
pull_request:
paths:
- '.github/workflows/csv-coverage-pr-comment.yml'
- '*/ql/src/**/*.ql'
- '*/ql/src/**/*.qll'
- 'misc/scripts/library-coverage/*.py'
# input data files
- '*/documentation/library-coverage/cwe-sink.csv'
- '*/documentation/library-coverage/frameworks.csv'
branches:
- main
- 'rc/*'
jobs:
generate:
name: Generate framework coverage artifacts
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github.event) }}
run: echo "$GITHUB_CONTEXT"
- name: Clone self (github/codeql) - MERGE
uses: actions/checkout@v2
with:
path: merge
- name: Clone self (github/codeql) - BASE
uses: actions/checkout@v2
with:
fetch-depth: 2
path: base
- run: |
git checkout HEAD^1
git log -1 --format='%H'
working-directory: base
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Download CodeQL CLI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release download --repo "github/codeql-cli-binaries" --pattern "codeql-linux64.zip"
- name: Unzip CodeQL CLI
run: unzip -d codeql-cli codeql-linux64.zip
- name: Generate CSV files on merge commit of the PR
run: |
echo "Running generator on merge"
PATH="$PATH:codeql-cli/codeql" python merge/misc/scripts/library-coverage/generate-report.py ci merge merge
mkdir out_merge
cp framework-coverage-*.csv out_merge/
cp framework-coverage-*.rst out_merge/
- name: Generate CSV files on base commit of the PR
run: |
echo "Running generator on base"
PATH="$PATH:codeql-cli/codeql" python base/misc/scripts/library-coverage/generate-report.py ci base base
mkdir out_base
cp framework-coverage-*.csv out_base/
cp framework-coverage-*.rst out_base/
- name: Generate diff of coverage reports
run: |
python base/misc/scripts/library-coverage/compare-folders.py out_base out_merge comparison.md
- name: Upload CSV package list
uses: actions/upload-artifact@v2
with:
name: csv-framework-coverage-merge
path: |
out_merge/framework-coverage-*.csv
out_merge/framework-coverage-*.rst
- name: Upload CSV package list
uses: actions/upload-artifact@v2
with:
name: csv-framework-coverage-base
path: |
out_base/framework-coverage-*.csv
out_base/framework-coverage-*.rst
- name: Upload comparison results
uses: actions/upload-artifact@v2
with:
name: comparison
path: |
comparison.md
- name: Save PR number
run: |
mkdir -p pr
echo ${{ github.event.pull_request.number }} > pr/NR
- name: Upload PR number
uses: actions/upload-artifact@v2
with:
name: pr
path: pr/

View File

@@ -0,0 +1,34 @@
name: Comment on PR with framework coverage changes
on:
workflow_run:
workflows: ["Check framework coverage changes"]
types:
- completed
jobs:
check:
name: Check framework coverage differences and comment
runs-on: ubuntu-latest
if: >
${{ github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github.event) }}
run: echo "$GITHUB_CONTEXT"
- name: Clone self (github/codeql)
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Check coverage difference file and comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: |
python misc/scripts/library-coverage/comment-pr.py "$GITHUB_REPOSITORY" "$RUN_ID"

View File

@@ -0,0 +1,42 @@
name: Build framework coverage timeseries reports
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone self (github/codeql)
uses: actions/checkout@v2
with:
path: script
- name: Clone self (github/codeql) for analysis
uses: actions/checkout@v2
with:
path: codeqlModels
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Download CodeQL CLI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release download --repo "github/codeql-cli-binaries" --pattern "codeql-linux64.zip"
- name: Unzip CodeQL CLI
run: unzip -d codeql-cli codeql-linux64.zip
- name: Build modeled package list
run: |
CLI=$(realpath "codeql-cli/codeql")
echo $CLI
PATH="$PATH:$CLI" python script/misc/scripts/library-coverage/generate-timeseries.py codeqlModels
- name: Upload timeseries CSV
uses: actions/upload-artifact@v2
with:
name: framework-coverage-timeseries
path: framework-coverage-timeseries-*.csv

View File

@@ -0,0 +1,44 @@
name: Update framework coverage reports
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs:
update:
name: Update framework coverage report
if: github.event.repository.fork == false
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github.event) }}
run: echo "$GITHUB_CONTEXT"
- name: Clone self (github/codeql)
uses: actions/checkout@v2
with:
path: ql
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Download CodeQL CLI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release download --repo "github/codeql-cli-binaries" --pattern "codeql-linux64.zip"
- name: Unzip CodeQL CLI
run: unzip -d codeql-cli codeql-linux64.zip
- name: Generate coverage files
run: |
PATH="$PATH:codeql-cli/codeql" python ql/misc/scripts/library-coverage/generate-report.py ci ql ql
- name: Create pull request with changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python ql/misc/scripts/library-coverage/create-pr.py ql "$GITHUB_REPOSITORY"

View File

@@ -1,4 +1,4 @@
name: Build/check CSV flow coverage report
name: Build framework coverage reports
on:
workflow_dispatch:
@@ -6,22 +6,6 @@ on:
qlModelShaOverride:
description: 'github/codeql repo SHA used for looking up the CSV models'
required: false
push:
branches:
- main
- 'rc/**'
pull_request:
paths:
- '.github/workflows/csv-coverage.yml'
- '*/ql/src/**/*.ql'
- '*/ql/src/**/*.qll'
- 'misc/scripts/library-coverage/*.py'
# input data files
- '*/documentation/library-coverage/cwe-sink.csv'
- '*/documentation/library-coverage/frameworks.csv'
# coverage report files
- '*/documentation/library-coverage/flow-model-coverage.csv'
- '*/documentation/library-coverage/flow-model-coverage.rst'
jobs:
build:
@@ -33,28 +17,20 @@ jobs:
uses: actions/checkout@v2
with:
path: script
- name: Clone self (github/codeql) at a given SHA for analysis
if: github.event.inputs.qlModelShaOverride != ''
uses: actions/checkout@v2
with:
path: codeqlModels
ref: github.event.inputs.qlModelShaOverride
- name: Clone self (github/codeql) for analysis
if: github.event.inputs.qlModelShaOverride == ''
uses: actions/checkout@v2
with:
path: codeqlModels
ref: ${{ github.event.inputs.qlModelShaOverride || github.ref }}
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Download CodeQL CLI
uses: dsaltares/fetch-gh-release-asset@aa37ae5c44d3c9820bc12fe675e8670ecd93bd1c
with:
repo: "github/codeql-cli-binaries"
version: "latest"
file: "codeql-linux64.zip"
token: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release download --repo "github/codeql-cli-binaries" --pattern "codeql-linux64.zip"
- name: Unzip CodeQL CLI
run: unzip -d codeql-cli codeql-linux64.zip
- name: Build modeled package list
@@ -63,15 +39,11 @@ jobs:
- name: Upload CSV package list
uses: actions/upload-artifact@v2
with:
name: csv-flow-model-coverage
path: flow-model-coverage-*.csv
name: framework-coverage-csv
path: framework-coverage-*.csv
- name: Upload RST package list
uses: actions/upload-artifact@v2
with:
name: rst-flow-model-coverage
path: flow-model-coverage-*.rst
# - name: Check coverage files
# if: github.event.pull_request
# run: |
# python script/misc/scripts/library-coverage/compare-files.py codeqlModels
name: framework-coverage-rst
path: framework-coverage-*.rst

View File

@@ -448,5 +448,17 @@
"SensitiveDataHeuristics Python/JS": [
"javascript/ql/src/semmle/javascript/security/internal/SensitiveDataHeuristics.qll",
"python/ql/src/semmle/python/security/internal/SensitiveDataHeuristics.qll"
],
"ReDoS Util Python/JS": [
"javascript/ql/src/semmle/javascript/security/performance/ReDoSUtil.qll",
"python/ql/src/semmle/python/security/performance/ReDoSUtil.qll"
],
"ReDoS Exponential Python/JS": [
"javascript/ql/src/semmle/javascript/security/performance/ExponentialBackTracking.qll",
"python/ql/src/semmle/python/security/performance/ExponentialBackTracking.qll"
],
"ReDoS Polynomial Python/JS": [
"javascript/ql/src/semmle/javascript/security/performance/SuperlinearBackTracking.qll",
"python/ql/src/semmle/python/security/performance/SuperlinearBackTracking.qll"
]
}

View File

@@ -0,0 +1,2 @@
lgtm,codescanning
* The "Use of a broken or risky cryptographic algorithm" (`cpp/weak-cryptographic-algorithm`) query has been further improved to reduce false positives and its `@precision` increased to `high`.

View File

@@ -0,0 +1,2 @@
lgtm,codescanning
* The DataFlow libraries have been augmented with support for `Configuration`-specific in-place read steps at, for example, sinks and custom taint steps. This means that it is now possible to specify sinks that accept flow with non-empty access paths.

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/offset-use-before-range-check
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.2
* @precision medium
* @tags reliability
* security

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/descriptor-may-not-be-closed
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @tags efficiency
* security
* external/cwe/cwe-775

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/descriptor-never-closed
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @tags efficiency
* security
* external/cwe/cwe-775

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/file-may-not-be-closed
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @tags efficiency
* security
* external/cwe/cwe-775

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/file-never-closed
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @tags efficiency
* security
* external/cwe/cwe-775

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/global-use-before-init
* @problem.severity warning
* @security-severity 6.9
* @security-severity 7.8
* @tags reliability
* security
* external/cwe/cwe-457

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/inconsistent-nullness-testing
* @problem.severity warning
* @security-severity 3.6
* @security-severity 7.5
* @tags reliability
* security
* external/cwe/cwe-476

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/initialization-not-run
* @problem.severity warning
* @security-severity 6.4
* @security-severity 7.5
* @tags reliability
* security
* external/cwe/cwe-456

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/late-negative-test
* @problem.severity warning
* @security-severity 10.0
* @security-severity 9.3
* @tags reliability
* security
* external/cwe/cwe-823

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/memory-may-not-be-freed
* @problem.severity warning
* @security-severity 3.6
* @security-severity 7.5
* @tags efficiency
* security
* external/cwe/cwe-401

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/memory-never-freed
* @problem.severity warning
* @security-severity 3.6
* @security-severity 7.5
* @tags efficiency
* security
* external/cwe/cwe-401

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/missing-negativity-test
* @problem.severity warning
* @security-severity 10.0
* @security-severity 9.3
* @tags reliability
* security
* external/cwe/cwe-823

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/missing-null-test
* @problem.severity recommendation
* @security-severity 3.6
* @security-severity 7.5
* @tags reliability
* security
* external/cwe/cwe-476

View File

@@ -3,7 +3,7 @@
* @description An object that was allocated with 'malloc' or 'new' is being freed using a mismatching 'free' or 'delete'.
* @kind problem
* @problem.severity warning
* @security-severity 3.6
* @security-severity 7.5
* @precision high
* @id cpp/new-free-mismatch
* @tags reliability

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/overflow-calculated
* @problem.severity warning
* @security-severity 5.9
* @security-severity 9.8
* @tags reliability
* security
* external/cwe/cwe-131

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/overflow-destination
* @problem.severity warning
* @security-severity 10.0
* @security-severity 9.3
* @precision low
* @tags reliability
* security

View File

@@ -4,7 +4,7 @@
* may result in a buffer overflow.
* @kind problem
* @problem.severity warning
* @security-severity 10.0
* @security-severity 9.3
* @precision medium
* @id cpp/static-buffer-overflow
* @tags reliability

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/return-stack-allocated-object
* @problem.severity warning
* @security-severity 2.9
* @security-severity 2.1
* @tags reliability
* security
* external/cwe/cwe-562

View File

@@ -4,7 +4,7 @@
* an instance of the type of the pointer may result in a buffer overflow
* @kind problem
* @problem.severity warning
* @security-severity 6.4
* @security-severity 8.1
* @precision medium
* @id cpp/allocation-too-small
* @tags reliability

View File

@@ -4,7 +4,7 @@
* multiple instances of the type of the pointer may result in a buffer overflow
* @kind problem
* @problem.severity warning
* @security-severity 6.4
* @security-severity 8.1
* @precision medium
* @id cpp/suspicious-allocation-size
* @tags reliability

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/use-after-free
* @problem.severity warning
* @security-severity 5.9
* @security-severity 9.3
* @tags reliability
* security
* external/cwe/cwe-416

View File

@@ -7,10 +7,6 @@
import cpp
class AnonymousCompilation extends Compilation {
override string toString() { result = "<compilation>" }
}
string describe(Compilation c) {
if c.getArgument(1) = "--mimic"
then result = "compiler invocation " + concat(int i | i > 1 | c.getArgument(i), " " order by i)
@@ -19,4 +15,4 @@ string describe(Compilation c) {
from Compilation c
where not c.normalTermination()
select c, "Extraction aborted for " + describe(c), 2
select "Extraction aborted for " + describe(c)

View File

@@ -6,7 +6,7 @@
* to a larger type.
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 8.1
* @precision very-high
* @id cpp/bad-addition-overflow-check
* @tags reliability

View File

@@ -4,7 +4,7 @@
* be a sign that the result can overflow the type converted from.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.1
* @precision high
* @id cpp/integer-multiplication-cast-to-long
* @tags reliability

View File

@@ -5,7 +5,7 @@
* unsigned integer values.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.1
* @precision high
* @id cpp/signed-overflow-check
* @tags correctness

View File

@@ -6,7 +6,7 @@
* use the width of the base type, leading to misaligned reads.
* @kind path-problem
* @problem.severity warning
* @security-severity 10.0
* @security-severity 9.3
* @precision high
* @id cpp/upcast-array-pointer-arithmetic
* @tags correctness

View File

@@ -6,7 +6,7 @@
* from an untrusted source, this can be used for exploits.
* @kind problem
* @problem.severity recommendation
* @security-severity 6.9
* @security-severity 9.3
* @precision high
* @id cpp/non-constant-format
* @tags maintainability

View File

@@ -3,7 +3,7 @@
* @description Using the return value from snprintf without proper checks can cause overflow.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.1
* @precision high
* @id cpp/overflowing-snprintf
* @tags reliability

View File

@@ -4,7 +4,7 @@
* a source of security issues.
* @kind problem
* @problem.severity error
* @security-severity 2.9
* @security-severity 5.0
* @precision high
* @id cpp/wrong-number-format-arguments
* @tags reliability

View File

@@ -4,7 +4,7 @@
* behavior.
* @kind problem
* @problem.severity error
* @security-severity 6.4
* @security-severity 7.5
* @precision high
* @id cpp/wrong-type-format-argument
* @tags reliability

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/incorrect-not-operator-usage
* @problem.severity warning
* @security-severity 3.6
* @security-severity 7.5
* @precision medium
* @tags security
* external/cwe/cwe-480

View File

@@ -3,7 +3,7 @@
* @description Using alloca in a loop can lead to a stack overflow
* @kind problem
* @problem.severity warning
* @security-severity 3.6
* @security-severity 7.5
* @precision high
* @id cpp/alloca-in-loop
* @tags reliability

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/improper-null-termination
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @tags security
* external/cwe/cwe-170
* external/cwe/cwe-665

View File

@@ -4,7 +4,7 @@
* on undefined behavior and may lead to memory corruption.
* @kind problem
* @problem.severity error
* @security-severity 2.9
* @security-severity 2.1
* @precision high
* @id cpp/pointer-overflow-check
* @tags reliability

View File

@@ -4,7 +4,7 @@
* as the third argument may result in a buffer overflow.
* @kind problem
* @problem.severity warning
* @security-severity 10.0
* @security-severity 9.3
* @precision medium
* @id cpp/bad-strncpy-size
* @tags reliability

View File

@@ -3,7 +3,7 @@
* @description Calling 'strncat' with an incorrect size argument may result in a buffer overflow.
* @kind problem
* @problem.severity warning
* @security-severity 10.0
* @security-severity 9.3
* @precision medium
* @id cpp/unsafe-strncat
* @tags reliability

View File

@@ -5,7 +5,7 @@
* the machine pointer size.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.8
* @precision medium
* @id cpp/suspicious-sizeof
* @tags reliability

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/uninitialized-local
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @precision medium
* @tags security
* external/cwe/cwe-665

View File

@@ -4,7 +4,7 @@
* may result in a buffer overflow
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 9.8
* @precision medium
* @id cpp/unsafe-strcat
* @tags reliability

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/self-assignment-check
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.0
* @tags reliability
* security
* external/cwe/cwe-826

View File

@@ -6,7 +6,7 @@
* @kind path-problem
* @id cpp/unsafe-use-of-this
* @problem.severity error
* @security-severity 3.6
* @security-severity 7.5
* @precision very-high
* @tags correctness
* language-features

View File

@@ -7,7 +7,7 @@
* undefined data.
* @kind problem
* @problem.severity error
* @security-severity 2.9
* @security-severity 5.0
* @precision very-high
* @id cpp/too-few-arguments
* @tags correctness

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/memset-may-be-deleted
* @problem.severity warning
* @security-severity 6.4
* @security-severity 7.8
* @precision high
* @tags security
* external/cwe/cwe-14

View File

@@ -5,7 +5,7 @@
* @kind path-problem
* @precision low
* @problem.severity error
* @security-severity 5.9
* @security-severity 7.8
* @tags security external/cwe/cwe-20
*/

View File

@@ -5,7 +5,7 @@
* @kind path-problem
* @precision low
* @problem.severity error
* @security-severity 5.9
* @security-severity 7.8
* @tags security external/cwe/cwe-20
*/

View File

@@ -4,7 +4,7 @@
* attacker to access unexpected resources.
* @kind path-problem
* @problem.severity warning
* @security-severity 6.4
* @security-severity 7.5
* @precision medium
* @id cpp/path-injection
* @tags security

View File

@@ -5,7 +5,7 @@
* to command injection.
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 9.8
* @precision low
* @id cpp/command-line-injection
* @tags security

View File

@@ -4,7 +4,7 @@
* allows for a cross-site scripting vulnerability.
* @kind path-problem
* @problem.severity error
* @security-severity 2.9
* @security-severity 6.1
* @precision high
* @id cpp/cgi-xss
* @tags security

View File

@@ -5,7 +5,7 @@
* to SQL Injection.
* @kind path-problem
* @problem.severity error
* @security-severity 6.4
* @security-severity 8.8
* @precision high
* @id cpp/sql-injection
* @tags security

View File

@@ -5,7 +5,7 @@
* commands.
* @kind path-problem
* @problem.severity warning
* @security-severity 6.0
* @security-severity 8.2
* @precision medium
* @id cpp/uncontrolled-process-operation
* @tags security

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/overflow-buffer
* @problem.severity recommendation
* @security-severity 10.0
* @security-severity 9.3
* @tags security
* external/cwe/cwe-119
* external/cwe/cwe-121

View File

@@ -5,7 +5,7 @@
* overflow.
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 9.3
* @precision high
* @id cpp/badly-bounded-write
* @tags reliability

View File

@@ -4,7 +4,7 @@
* of data written may overflow.
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 9.3
* @precision medium
* @id cpp/overrunning-write
* @tags reliability

View File

@@ -5,7 +5,7 @@
* take extreme values.
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 9.3
* @precision medium
* @id cpp/overrunning-write-with-float
* @tags reliability

View File

@@ -4,7 +4,7 @@
* of data written may overflow.
* @kind path-problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 9.3
* @precision medium
* @id cpp/unbounded-write
* @tags reliability

View File

@@ -5,7 +5,7 @@
* a specific value to terminate the argument list.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.8
* @precision medium
* @id cpp/unterminated-variadic-call
* @tags reliability

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/unclear-array-index-validation
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.8
* @tags security
* external/cwe/cwe-129
*/

View File

@@ -5,7 +5,7 @@
* terminator can cause a buffer overrun.
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 9.8
* @precision high
* @id cpp/no-space-for-terminator
* @tags reliability

View File

@@ -5,7 +5,7 @@
* or data representation problems.
* @kind path-problem
* @problem.severity warning
* @security-severity 6.9
* @security-severity 9.3
* @precision high
* @id cpp/tainted-format-string
* @tags reliability

View File

@@ -5,7 +5,7 @@
* or data representation problems.
* @kind path-problem
* @problem.severity warning
* @security-severity 6.9
* @security-severity 9.3
* @precision high
* @id cpp/tainted-format-string-through-global
* @tags reliability

View File

@@ -2,9 +2,9 @@
* @name User-controlled data in arithmetic expression
* @description Arithmetic operations on user-controlled data that is
* not validated can cause overflows.
* @kind problem
* @kind path-problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.6
* @precision low
* @id cpp/tainted-arithmetic
* @tags security
@@ -16,22 +16,39 @@ import cpp
import semmle.code.cpp.security.Overflow
import semmle.code.cpp.security.Security
import semmle.code.cpp.security.TaintTracking
import TaintedWithPath
import Bounded
from Expr origin, Operation op, Expr e, string effect
bindingset[op]
predicate missingGuard(Operation op, Expr e, string effect) {
missingGuardAgainstUnderflow(op, e) and effect = "underflow"
or
missingGuardAgainstOverflow(op, e) and effect = "overflow"
or
not e instanceof VariableAccess and effect = "overflow"
}
class Configuration extends TaintTrackingConfiguration {
override predicate isSink(Element e) {
exists(Operation op |
missingGuard(op, e, _) and
op.getAnOperand() = e
|
op instanceof UnaryArithmeticOperation or
op instanceof BinaryArithmeticOperation
)
}
override predicate isBarrier(Expr e) {
super.isBarrier(e) or bounded(e) or e.getUnspecifiedType().(IntegralType).getSize() <= 1
}
}
from Expr origin, Expr e, string effect, PathNode sourceNode, PathNode sinkNode, Operation op
where
isUserInput(origin, _) and
tainted(origin, e) and
taintedWithPath(origin, e, sourceNode, sinkNode) and
op.getAnOperand() = e and
(
missingGuardAgainstUnderflow(op, e) and effect = "underflow"
or
missingGuardAgainstOverflow(op, e) and effect = "overflow"
or
not e instanceof VariableAccess and effect = "overflow"
) and
(
op instanceof UnaryArithmeticOperation or
op instanceof BinaryArithmeticOperation
)
select e, "$@ flows to here and is used in arithmetic, potentially causing an " + effect + ".",
origin, "User-provided value"
missingGuard(op, e, effect)
select e, sourceNode, sinkNode,
"$@ flows to here and is used in arithmetic, potentially causing an " + effect + ".", origin,
"User-provided value"

View File

@@ -4,7 +4,7 @@
* validated can cause overflows.
* @kind path-problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.6
* @precision medium
* @id cpp/uncontrolled-arithmetic
* @tags security
@@ -16,8 +16,8 @@ import cpp
import semmle.code.cpp.security.Overflow
import semmle.code.cpp.security.Security
import semmle.code.cpp.security.TaintTracking
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
import TaintedWithPath
import Bounded
predicate isUnboundedRandCall(FunctionCall fc) {
exists(Function func | func = fc.getTarget() |
@@ -27,74 +27,6 @@ predicate isUnboundedRandCall(FunctionCall fc) {
)
}
/**
* An operand `e` of a division expression (i.e., `e` is an operand of either a `DivExpr` or
* a `AssignDivExpr`) is bounded when `e` is the left-hand side of the division.
*/
pragma[inline]
predicate boundedDiv(Expr e, Expr left) { e = left }
/**
* An operand `e` of a remainder expression `rem` (i.e., `rem` is either a `RemExpr` or
* an `AssignRemExpr`) with left-hand side `left` and right-ahnd side `right` is bounded
* when `e` is `left` and `right` is upper bounded by some number that is less than the maximum integer
* allowed by the result type of `rem`.
*/
pragma[inline]
predicate boundedRem(Expr e, Expr rem, Expr left, Expr right) {
e = left and
upperBound(right.getFullyConverted()) < exprMaxVal(rem.getFullyConverted())
}
/**
* An operand `e` of a bitwise and expression `andExpr` (i.e., `andExpr` is either an `BitwiseAndExpr`
* or an `AssignAndExpr`) with operands `operand1` and `operand2` is the operand that is not `e` is upper
* bounded by some number that is less than the maximum integer allowed by the result type of `andExpr`.
*/
pragma[inline]
predicate boundedBitwiseAnd(Expr e, Expr andExpr, Expr operand1, Expr operand2) {
operand1 != operand2 and
e = operand1 and
upperBound(operand2.getFullyConverted()) < exprMaxVal(andExpr.getFullyConverted())
}
/**
* Holds if `fc` is a part of the left operand of a binary operation that greatly reduces the range
* of possible values.
*/
predicate bounded(Expr e) {
// For `%` and `&` we require that `e` is bounded by a value that is strictly smaller than the
// maximum possible value of the result type of the operation.
// For example, the function call `rand()` is considered bounded in the following program:
// ```
// int i = rand() % (UINT8_MAX + 1);
// ```
// but not in:
// ```
// unsigned char uc = rand() % (UINT8_MAX + 1);
// ```
exists(RemExpr rem | boundedRem(e, rem, rem.getLeftOperand(), rem.getRightOperand()))
or
exists(AssignRemExpr rem | boundedRem(e, rem, rem.getLValue(), rem.getRValue()))
or
exists(BitwiseAndExpr andExpr |
boundedBitwiseAnd(e, andExpr, andExpr.getAnOperand(), andExpr.getAnOperand())
)
or
exists(AssignAndExpr andExpr |
boundedBitwiseAnd(e, andExpr, andExpr.getAnOperand(), andExpr.getAnOperand())
)
or
// Optimitically assume that a division always yields a much smaller value.
boundedDiv(e, any(DivExpr div).getLeftOperand())
or
boundedDiv(e, any(AssignDivExpr div).getLValue())
or
boundedDiv(e, any(RShiftExpr shift).getLeftOperand())
or
boundedDiv(e, any(AssignRShiftExpr div).getLValue())
}
predicate isUnboundedRandCallOrParent(Expr e) {
isUnboundedRandCall(e)
or

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/arithmetic-with-extreme-values
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.6
* @precision low
* @tags security
* reliability

View File

@@ -0,0 +1,83 @@
/**
* This file provides the `bounded` predicate that is used in both `cpp/uncontrolled-arithmetic`
* and `cpp/tainted-arithmetic`.
*/
private import cpp
private import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
private import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
/**
* An operand `e` of a division expression (i.e., `e` is an operand of either a `DivExpr` or
* a `AssignDivExpr`) is bounded when `e` is the left-hand side of the division.
*/
pragma[inline]
private predicate boundedDiv(Expr e, Expr left) { e = left }
/**
* An operand `e` of a remainder expression `rem` (i.e., `rem` is either a `RemExpr` or
* an `AssignRemExpr`) with left-hand side `left` and right-ahnd side `right` is bounded
* when `e` is `left` and `right` is upper bounded by some number that is less than the maximum integer
* allowed by the result type of `rem`.
*/
pragma[inline]
private predicate boundedRem(Expr e, Expr rem, Expr left, Expr right) {
e = left and
upperBound(right.getFullyConverted()) < exprMaxVal(rem.getFullyConverted())
}
/**
* An operand `e` of a bitwise and expression `andExpr` (i.e., `andExpr` is either an `BitwiseAndExpr`
* or an `AssignAndExpr`) with operands `operand1` and `operand2` is the operand that is not `e` is upper
* bounded by some number that is less than the maximum integer allowed by the result type of `andExpr`.
*/
pragma[inline]
private predicate boundedBitwiseAnd(Expr e, Expr andExpr, Expr operand1, Expr operand2) {
operand1 != operand2 and
e = operand1 and
upperBound(operand2.getFullyConverted()) < exprMaxVal(andExpr.getFullyConverted())
}
/**
* Holds if `e` is an arithmetic expression that cannot overflow, or if `e` is an operand of an
* operation that may greatly reduce the range of possible values.
*/
predicate bounded(Expr e) {
(
e instanceof UnaryArithmeticOperation or
e instanceof BinaryArithmeticOperation or
e instanceof AssignArithmeticOperation
) and
not convertedExprMightOverflow(e)
or
// For `%` and `&` we require that `e` is bounded by a value that is strictly smaller than the
// maximum possible value of the result type of the operation.
// For example, the function call `rand()` is considered bounded in the following program:
// ```
// int i = rand() % (UINT8_MAX + 1);
// ```
// but not in:
// ```
// unsigned char uc = rand() % (UINT8_MAX + 1);
// ```
exists(RemExpr rem | boundedRem(e, rem, rem.getLeftOperand(), rem.getRightOperand()))
or
exists(AssignRemExpr rem | boundedRem(e, rem, rem.getLValue(), rem.getRValue()))
or
exists(BitwiseAndExpr andExpr |
boundedBitwiseAnd(e, andExpr, andExpr.getAnOperand(), andExpr.getAnOperand())
)
or
exists(AssignAndExpr andExpr |
boundedBitwiseAnd(e, andExpr, andExpr.getAnOperand(), andExpr.getAnOperand())
)
or
// Optimitically assume that a division always yields a much smaller value.
boundedDiv(e, any(DivExpr div).getLeftOperand())
or
boundedDiv(e, any(AssignDivExpr div).getLValue())
or
boundedDiv(e, any(RShiftExpr shift).getLeftOperand())
or
boundedDiv(e, any(AssignRShiftExpr div).getLValue())
}

View File

@@ -5,7 +5,7 @@
* @id cpp/comparison-with-wider-type
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @precision high
* @tags reliability
* security

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/integer-overflow-tainted
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.1
* @precision low
* @tags security
* external/cwe/cwe-190

View File

@@ -4,7 +4,7 @@
* user can result in integer overflow.
* @kind path-problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 8.1
* @precision medium
* @id cpp/uncontrolled-allocation-size
* @tags reliability

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/unsigned-difference-expression-compared-zero
* @problem.severity warning
* @security-severity 5.9
* @security-severity 9.8
* @precision medium
* @tags security
* correctness

View File

@@ -4,7 +4,7 @@
* @kind problem
* @id cpp/hresult-boolean-conversion
* @problem.severity error
* @security-severity 4.2
* @security-severity 7.5
* @precision high
* @tags security
* external/cwe/cwe-253

View File

@@ -5,7 +5,7 @@
* vulnerable to spoofing attacks.
* @kind path-problem
* @problem.severity warning
* @security-severity 5.8
* @security-severity 8.1
* @precision medium
* @id cpp/user-controlled-bypass
* @tags security

View File

@@ -4,7 +4,7 @@
* to an attacker.
* @kind path-problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.5
* @precision medium
* @id cpp/cleartext-storage-buffer
* @tags security

View File

@@ -4,7 +4,7 @@
* to an attacker.
* @kind problem
* @problem.severity warning
* @security-severity 6.4
* @security-severity 7.5
* @precision medium
* @id cpp/cleartext-storage-file
* @tags security

View File

@@ -4,7 +4,7 @@
* database can expose it to an attacker.
* @kind path-problem
* @problem.severity warning
* @security-severity 6.4
* @security-severity 7.5
* @precision medium
* @id cpp/cleartext-storage-database
* @tags security

View File

@@ -4,8 +4,8 @@
* an attacker to compromise security.
* @kind problem
* @problem.severity error
* @security-severity 5.2
* @precision medium
* @security-severity 7.5
* @precision high
* @id cpp/weak-cryptographic-algorithm
* @tags security
* external/cwe/cwe-327
@@ -70,9 +70,12 @@ EnumConstant getAdditionalEvidenceEnumConst() { isEncryptionAdditionalEvidence(r
predicate getInsecureEncryptionEvidence(FunctionCall fc, Element blame, string description) {
// find use of an insecure algorithm name
(
fc.getTarget() = getAnInsecureEncryptionFunction() and
blame = fc and
description = "call to " + fc.getTarget().getName()
exists(FunctionCall fc2 |
fc.getAChild*() = fc2 and
fc2.getTarget() = getAnInsecureEncryptionFunction() and
blame = fc2 and
description = "call to " + fc.getTarget().getName()
)
or
exists(MacroInvocation mi |
(
@@ -93,7 +96,10 @@ predicate getInsecureEncryptionEvidence(FunctionCall fc, Element blame, string d
) and
// find additional evidence that this function is related to encryption.
(
fc.getTarget() = getAnAdditionalEvidenceFunction()
exists(FunctionCall fc2 |
fc.getAChild*() = fc2 and
fc2.getTarget() = getAnAdditionalEvidenceFunction()
)
or
exists(MacroInvocation mi |
(
@@ -107,6 +113,27 @@ predicate getInsecureEncryptionEvidence(FunctionCall fc, Element blame, string d
ec = fc.getAnArgument() and
ec.getTarget() = getAdditionalEvidenceEnumConst()
)
) and
// exclude calls from templates as this is rarely the right place to flag an
// issue
not fc.isFromTemplateInstantiation(_) and
(
// the function should have an input that looks like a non-constant buffer
exists(Expr e |
fc.getAnArgument() = e and
(
e.getUnspecifiedType() instanceof PointerType or
e.getUnspecifiedType() instanceof ReferenceType or
e.getUnspecifiedType() instanceof ArrayType
) and
not e.getType().isDeeplyConstBelow() and
not e.isConstant()
)
or
// or be a non-const member function of an object
fc.getTarget() instanceof MemberFunction and
not fc.getTarget() instanceof ConstMemberFunction and
not fc.getTarget().isStatic()
)
}

View File

@@ -4,7 +4,7 @@
* attackers to retrieve portions of memory.
* @kind problem
* @problem.severity error
* @security-severity 5.2
* @security-severity 7.5
* @precision very-high
* @id cpp/openssl-heartbleed
* @tags security

View File

@@ -5,7 +5,7 @@
* the two operations.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.7
* @precision medium
* @id cpp/toctou-race-condition
* @tags security

View File

@@ -4,7 +4,7 @@
* @id cpp/unsafe-create-process-call
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 7.8
* @precision medium
* @msrc.severity important
* @tags security

View File

@@ -5,7 +5,7 @@
* state, and reading the variable may result in undefined behavior.
* @kind problem
* @problem.severity warning
* @security-severity 6.9
* @security-severity 7.8
* @opaque-id SM02313
* @id cpp/conditionally-uninitialized-variable
* @tags security

View File

@@ -4,7 +4,7 @@
* can cause buffer overflow conditions.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.8
* @precision medium
* @id cpp/suspicious-pointer-scaling
* @tags security

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/incorrect-pointer-scaling-char
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.8
* @precision low
* @tags security
* external/cwe/cwe-468

View File

@@ -4,7 +4,7 @@
* can cause buffer overflow conditions.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.8
* @precision medium
* @id cpp/suspicious-pointer-scaling-void
* @tags security

View File

@@ -5,7 +5,7 @@
* implicitly scaled.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 8.8
* @precision high
* @id cpp/suspicious-add-sizeof
* @tags security

View File

@@ -5,7 +5,7 @@
* attack plan.
* @kind problem
* @problem.severity warning
* @security-severity 3.6
* @security-severity 6.5
* @precision medium
* @id cpp/system-data-exposure
* @tags security

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/incorrect-string-type-conversion
* @problem.severity error
* @security-severity 5.9
* @security-severity 8.8
* @precision high
* @tags security
* external/cwe/cwe-704

View File

@@ -3,7 +3,7 @@
* @description Creating a file that is world-writable can allow an attacker to write to the file.
* @kind problem
* @problem.severity warning
* @security-severity 5.9
* @security-severity 7.8
* @precision medium
* @id cpp/world-writable-file-creation
* @tags security

View File

@@ -7,7 +7,7 @@
* @id cpp/unsafe-dacl-security-descriptor
* @kind problem
* @problem.severity error
* @security-severity 5.9
* @security-severity 7.8
* @precision high
* @tags security
* external/cwe/cwe-732

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/lock-order-cycle
* @problem.severity error
* @security-severity 6.9
* @security-severity 5.0
* @tags security
* external/cwe/cwe-764
* external/cwe/cwe-833

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/twice-locked
* @problem.severity error
* @security-severity 6.9
* @security-severity 5.0
* @precision low
* @tags security
* external/cwe/cwe-764

View File

@@ -5,7 +5,7 @@
* @kind problem
* @id cpp/unreleased-lock
* @problem.severity error
* @security-severity 6.9
* @security-severity 5.0
* @precision low
* @tags security
* external/cwe/cwe-764

View File

@@ -5,7 +5,7 @@
* attack.
* @kind path-problem
* @problem.severity warning
* @security-severity 6.4
* @security-severity 7.5
* @precision medium
* @id cpp/tainted-permissions-check
* @tags security

View File

@@ -6,7 +6,7 @@
* @kind problem
* @id cpp/infinite-loop-with-unsatisfiable-exit-condition
* @problem.severity warning
* @security-severity 3.6
* @security-severity 7.5
* @tags security
* external/cwe/cwe-835
*/

View File

@@ -4,7 +4,6 @@
* @description The total number of lines of C/C++ code across all files, including system headers, libraries, and auto-generated files. This is a useful metric of the size of a database. For all files that were seen during the build, this query counts the lines of code, excluding whitespace or comments.
* @kind metric
* @tags summary
* lines-of-code
*/
import cpp

Some files were not shown because too many files have changed in this diff Show More