Skip to content

Commit aea7bf1

Browse files
committed
Add CodeQL query to check allocations do not exceed ensure_free
The query also checks redundant ensure_free calls, i.e. calls followed by another call with no allocation in between. Fix errors found by the query: - Add a missing ensure_free in esp32 `dac_driver.c` - Fix and simplify allocation in `adc_driver.c` (fix misplaced parenthesis bug and merge two ensure_free calls into one) - Remove redundant ensure_free calls in `otp_ssl.c` (left over from removal of `enif_make_resource` which used to do its own ensure_free) - Remove a redundant ensure_free call in `nif_erlang_fun_to_list` Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent d2d58f5 commit aea7bf1

File tree

10 files changed

+557
-45
lines changed

10 files changed

+557
-45
lines changed

.github/workflows/codeql-analysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
with:
6666
languages: ${{ matrix.language }}
6767
build-mode: manual
68-
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql
68+
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql,./code-queries/allocations-exceeding-ensure-free.ql
6969

7070
- name: "Build"
7171
run: |

.github/workflows/esp32-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
with:
7575
languages: "cpp"
7676
build-mode: manual
77-
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql
77+
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql,./code-queries/allocations-exceeding-ensure-free.ql
7878

7979
- name: Build with idf.py
8080
shell: bash

.github/workflows/pico-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
with:
163163
languages: "cpp"
164164
build-mode: manual
165-
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql
165+
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql,./code-queries/allocations-exceeding-ensure-free.ql
166166

167167
- name: Build
168168
shell: bash

.github/workflows/stm32-build.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ jobs:
124124
- name: Checkout repo
125125
uses: actions/checkout@v4
126126

127+
- name: "Git config safe.directory for codeql"
128+
run: git config --global --add safe.directory /__w/AtomVM/AtomVM
129+
130+
- name: "Initialize CodeQL"
131+
uses: github/codeql-action/init@v4
132+
with:
133+
languages: 'cpp'
134+
build-mode: manual
135+
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql,./code-queries/allocations-exceeding-ensure-free.ql
136+
127137
- name: "Build for ${{ matrix.device }}"
128138
shell: bash
129139
working-directory: ./src/platforms/stm32/
@@ -134,6 +144,9 @@ jobs:
134144
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=cmake/arm-toolchain.cmake -DDEVICE=${{ matrix.device }}
135145
cmake --build .
136146
147+
- name: "Perform CodeQL Analysis"
148+
uses: github/codeql-action/analyze@v4
149+
137150
- name: "Check firmware size for ${{ matrix.device }}"
138151
shell: bash
139152
working-directory: ./src/platforms/stm32/build

.github/workflows/wasm-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
with:
6363
languages: ${{matrix.language}}
6464
build-mode: manual
65-
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql
65+
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql,./code-queries/allocations-exceeding-ensure-free.ql
6666

6767
- name: Compile AtomVM and test modules
6868
run: |

0 commit comments

Comments
 (0)