github: Add CodeQL workflow
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
queries:
|
||||
- uses: ./.github/codeql/cpp-queries
|
||||
|
||||
query-filters:
|
||||
# don't explicitly point out FIXME comments
|
||||
- exclude:
|
||||
id: cpp/fixme-comment
|
||||
# this rule produces too many false positives due to our custom specifiers and
|
||||
# the use of void pointers in swanctl
|
||||
- exclude:
|
||||
id: cpp/wrong-type-format-argument
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @name Invalid use of chunk_from_chars() macro
|
||||
* @description The chunk_from_chars() macro creates a temporary chunk_t, which
|
||||
* is not defined outside of the block in which it has been used,
|
||||
* therefore, compilers might optimize out the assignment.
|
||||
* @kind path-problem
|
||||
* @problem.severity error
|
||||
* @id strongswan/invalid-chunk-from-chars
|
||||
* @tags correctness
|
||||
* @precision very-high
|
||||
*/
|
||||
import cpp
|
||||
import DataFlow::PathGraph
|
||||
import semmle.code.cpp.dataflow.DataFlow
|
||||
|
||||
class ChunkFromChars extends Expr {
|
||||
ChunkFromChars() {
|
||||
this = any(MacroInvocation mi |
|
||||
mi.getOutermostMacroAccess().getMacroName() = "chunk_from_chars"
|
||||
/* ignore global static uses of the macro */
|
||||
and exists (BlockStmt b | mi.getExpr().getEnclosingBlock() = b)
|
||||
).getExpr()
|
||||
}
|
||||
}
|
||||
|
||||
class ChunkFromCharsUsage extends DataFlow::Configuration {
|
||||
ChunkFromCharsUsage() { this = "ChunkFromCharsUsage" }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) {
|
||||
source.asExpr() instanceof ChunkFromChars
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
exists(sink.asExpr())
|
||||
}
|
||||
|
||||
override predicate isBarrierOut(DataFlow::Node node) {
|
||||
/* don't track beyond function calls */
|
||||
exists(FunctionCall fc | node.asExpr().getParent*() = fc)
|
||||
}
|
||||
}
|
||||
|
||||
BlockStmt enclosingBlock(BlockStmt b) {
|
||||
result = b.getEnclosingBlock()
|
||||
}
|
||||
|
||||
from ChunkFromCharsUsage usage, DataFlow::PathNode source, DataFlow::PathNode sink
|
||||
where
|
||||
usage.hasFlowPath(source, sink)
|
||||
and not source.getNode().asExpr().getEnclosingBlock() = enclosingBlock*(sink.getNode().asExpr().getEnclosingBlock())
|
||||
select source, source, sink, "Invalid use of chunk_from_chars() result in sibling/parent block."
|
||||
@@ -0,0 +1,3 @@
|
||||
name: strongswan/cpp-queries
|
||||
dependencies:
|
||||
codeql/cpp-all: "*"
|
||||
@@ -0,0 +1,72 @@
|
||||
name: "CodeQL"
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
CCACHE_BASEDIR: ${{ github.workspace }}
|
||||
CCACHE_COMPRESS: true
|
||||
CCACHE_MAXSIZE: 200M
|
||||
OS_NAME: linux
|
||||
|
||||
jobs:
|
||||
pre-check:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
should_skip: ${{ steps.skip-check.outputs.should_skip }}
|
||||
steps:
|
||||
- id: skip-check
|
||||
uses: fkirc/skip-duplicate-actions@master
|
||||
with:
|
||||
concurrent_skipping: 'same_content'
|
||||
|
||||
analyze:
|
||||
needs: pre-check
|
||||
if: ${{ needs.pre-check.outputs.should_skip != 'true' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'cpp', 'python', 'ruby' ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
config-file: ./.github/codeql/config.yml
|
||||
|
||||
- if: matrix.language == 'python' || matrix.language == 'ruby'
|
||||
name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# this follows the steps of the Linux workflow
|
||||
- if: matrix.language == 'cpp'
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.cache/ccache
|
||||
key: ccache-ubuntu-latest-gcc-codeql-${{ github.sha }}
|
||||
restore-keys: |
|
||||
ccache-ubuntu-latest-gcc-codeql
|
||||
ccache-ubuntu-latest-gcc-all-${{ github.sha }}
|
||||
ccache-ubuntu-latest-gcc-all-
|
||||
ccache-ubuntu-latest-gcc-
|
||||
- if: matrix.language == 'cpp'
|
||||
run: |
|
||||
sudo apt-get install -qq ccache
|
||||
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
|
||||
ccache -z
|
||||
- if: matrix.language == 'cpp'
|
||||
env:
|
||||
TEST: codeql
|
||||
uses: ./.github/actions/default
|
||||
- if: matrix.language == 'cpp'
|
||||
run: ccache -s
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
||||
Reference in New Issue
Block a user