Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit a17d3c7

Browse files
committed
Add CI-Testing with course answers
1 parent 6c423b0 commit a17d3c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1009
-7
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Build and publish docker images to registry
2+
3+
on: [push]
4+
5+
jobs:
6+
# TODO: make this use any changes in codeql-learninglab-check
7+
test-courses-cpp-ctf-segv:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v1
12+
13+
- name: Build Course Docker Image
14+
run: cd courses/cpp/ctf-segv/image && ./build.sh
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

codeql-learninglab-check/package/src/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ const writeFile = promisify(fs.writeFile);
2222
*/
2323
const RUN_ALL = process.env.RUN_ALL === 'true';
2424

25+
/**
26+
* Set to true to avoid using the GitHub API to post a comment
27+
* (used when running the script in CI)
28+
*/
29+
const SKIP_COMMENT = process.env.SKIP_COMMENT === 'true';
30+
2531
/**
2632
* The GITHUB_TOKEN secret
2733
*/
@@ -97,13 +103,16 @@ function isConfig(config: any): config is Config {
97103

98104
let comment = '';
99105

100-
const end = () =>
101-
api.repos.createCommitComment({
102-
body: comment,
103-
owner: event.repository.owner.login,
104-
repo: event.repository.name,
105-
commit_sha: event.after
106-
});
106+
const end = () => {
107+
if (!SKIP_COMMENT) {
108+
api.repos.createCommitComment({
109+
body: comment,
110+
owner: event.repository.owner.login,
111+
repo: event.repository.name,
112+
commit_sha: event.after
113+
});
114+
}
115+
}
107116

108117
/**
109118
* File paths changed by the user (if we're not just running all queries)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @name 00_alloca_definition
3+
* @description Find the definition of the alloca macro
4+
* @kind problem
5+
*/
6+
7+
import cpp
8+
9+
from Function f
10+
where f.getName() = "getchar"
11+
select f, "a getchar function"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @name 01_alloca_definition
3+
* @description Find the definition of the alloca macro
4+
* @kind problem
5+
* @problem.severity warning
6+
*/
7+
8+
import cpp
9+
10+
from Macro alloca
11+
where alloca.getName() = "alloca"
12+
select alloca, "alloca macro"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @name 10_alloca
3+
* @description Find all calls to alloca
4+
* @kind problem
5+
* @problem.severity warning
6+
*/
7+
8+
import cpp
9+
10+
from FunctionCall alloca
11+
where alloca.getTarget().getName() = "__builtin_alloca"
12+
select alloca, "call to alloca"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name 11_alloca_ignore_small
3+
* @description Find all calls to alloca, with small allocation sizes filtered out.
4+
* @kind problem
5+
* @problem.severity warning
6+
*/
7+
8+
import cpp
9+
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
10+
11+
from FunctionCall alloca, Expr sizeArg
12+
where
13+
alloca.getTarget().getName() = "__builtin_alloca" and
14+
sizeArg = alloca.getArgument(0) and
15+
(lowerBound(sizeArg) < 0 or 65536 <= upperBound(sizeArg))
16+
select alloca, "call to alloca"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name 20_use_alloca
3+
* @description Find all calls to __libc_use_alloca
4+
* @kind problem
5+
* @problem.severity warning
6+
*/
7+
8+
import cpp
9+
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
10+
11+
from FunctionCall call
12+
where call.getTarget().getName() = "__libc_use_alloca"
13+
select call, "call to __libc_use_alloca"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name 21_use_alloca_guard
3+
* @description Find all guard conditions where the condition is a call to
4+
* __libc_use_alloca.
5+
* @kind problem
6+
* @problem.severity warning
7+
*/
8+
9+
import cpp
10+
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
11+
import semmle.code.cpp.controlflow.Guards
12+
13+
from GuardCondition guard
14+
where guard.(FunctionCall).getTarget().getName() = "__libc_use_alloca"
15+
select guard, "__libc_use_alloca guard"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name 22_use_alloca_guard
3+
* @description Find all guard conditions where the condition is a call to
4+
* __libc_use_alloca.
5+
* @kind problem
6+
* @problem.severity warning
7+
*/
8+
9+
import cpp
10+
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
11+
import semmle.code.cpp.controlflow.Guards
12+
import semmle.code.cpp.dataflow.DataFlow
13+
14+
from DataFlow::Node source, DataFlow::Node sink
15+
where
16+
source.asExpr().(FunctionCall).getTarget().getName() = "__libc_use_alloca" and
17+
sink.asExpr() instanceof GuardCondition and
18+
DataFlow::localFlow(source, sink)
19+
select sink, "__libc_use_alloca guard"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @name 23_use_alloca_guard
3+
* @description Find all guard conditions where the condition is a call to
4+
* __libc_use_alloca.
5+
* @kind problem
6+
* @problem.severity warning
7+
*/
8+
9+
import cpp
10+
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
11+
import semmle.code.cpp.controlflow.Guards
12+
import semmle.code.cpp.dataflow.DataFlow
13+
14+
DataFlow::Node use_alloca() {
15+
result.asExpr().(FunctionCall).getTarget().getName() = "__libc_use_alloca"
16+
or
17+
result.asExpr().(FunctionCall).getTarget().getName() = "__builtin_expect" and
18+
result.asExpr().(FunctionCall).getArgument(0) = use_alloca().asExpr()
19+
or
20+
DataFlow::localFlow(use_alloca(), result)
21+
}
22+
23+
from GuardCondition guard
24+
where guard = use_alloca().asExpr()
25+
select guard, "__libc_use_alloca guard"

0 commit comments

Comments
 (0)