Skip to content

Commit 9876275

Browse files
authored
Update CodeQL scan (#2049)
1 parent c7cc7fe commit 9876275

23 files changed

Lines changed: 446 additions & 72 deletions

File tree

‎.github/config/codeql.yml‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
name: "CodeQL config"
2+
3+
# 1. Used by Python & JavaScript (and uncompiled headers in C++)
24
paths-ignore:
3-
- 'dependencies/external/'
4-
- 'assets/webconfig/js/lib'
5-
- 'build/**'
5+
- 'dependencies/**'
6+
- '**/dependencies/**'
7+
- 'assets/webconfig/js/lib/**'
8+
9+
# 2. Used during Query Evaluation for C++ (and Python/JS)
10+
query-filters:
11+
- exclude:
12+
path: 'dependencies/**'
13+
- exclude:
14+
path: '**/dependencies/**'
15+
- exclude:
16+
path: 'build/**'
17+
- exclude:
18+
path: '**/build/**'

‎.github/workflows/codeql.yml‎

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
analyze:
17-
name: 📊 Analyze
17+
name: 📊 Analyze (${{ matrix.language }})
1818
runs-on: ubuntu-latest
1919
permissions:
2020
actions: read
@@ -24,32 +24,44 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
language: [ python, javascript, cpp ]
27+
include:
28+
- language: python
29+
build-mode: none
30+
container: ~
31+
- language: javascript
32+
build-mode: none
33+
container: ~
34+
- language: cpp
35+
build-mode: manual
36+
container:
37+
image: ghcr.io/hyperion-project/debian:bookworm-qt6
38+
options: -v /__t/CodeQL:/__t/CodeQL -v /opt/hostedtoolcache/CodeQL:/opt/hostedtoolcache/CodeQL
2839

29-
container:
30-
image: ghcr.io/hyperion-project/debian:bookworm-qt6
40+
container: ${{ matrix.container }}
3141

3242
steps:
3343
- name: ⬇ Checkout
3444
uses: actions/checkout@v7
3545
with:
3646
submodules: recursive
3747

48+
- name: ⚙️ Mark Workspace Safe for Git
49+
if: ${{ matrix.language == 'cpp' }}
50+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
51+
3852
- name: 🔁 Initialize CodeQL
3953
uses: github/codeql-action/init@v4.37.9
4054
with:
4155
languages: ${{ matrix.language }}
56+
build-mode: ${{ matrix.build-mode }}
4257
queries: +security-and-quality
4358
config-file: ./.github/config/codeql.yml
4459

45-
- name: 👷 Build (Python & JavaScript)
46-
if: ${{ matrix.language != 'cpp' }}
47-
uses: github/codeql-action/autobuild@v4.37.9
48-
49-
- name: 📥 Install jq (C++)
60+
- name: 📥 Install jq & Pre-Build Deps (C++)
5061
if: ${{ matrix.language == 'cpp' }}
5162
shell: bash
52-
run: apt-get update && apt-get install -y jq
63+
run: |
64+
apt-get update && apt-get install -y jq
5365
5466
- name: 💾 Download Pre-Build Dependencies (C++)
5567
if: ${{ matrix.language == 'cpp' }}
@@ -58,16 +70,29 @@ jobs:
5870
with:
5971
os: 'debian_bookworm'
6072
architecture: 'amd64'
61-
qt_version: '6'
6273
build_type: ${{ github.event_name == 'pull_request' && 'debug' || 'release' }}
6374

75+
- name: ⚡ Setup ccache
76+
if: ${{ matrix.language == 'cpp' }}
77+
uses: hendrikmuhs/ccache-action@v1.2.24
78+
with:
79+
key: ${{ runner.os }}-codeql-ccache-${{ github.ref }}
80+
restore-keys: |
81+
${{ runner.os }}-codeql-ccache-master
82+
${{ runner.os }}-codeql-ccache-
83+
6484
- name: 👷 Build (C++)
6585
if: ${{ matrix.language == 'cpp' }}
6686
run: |
67-
cmake --preset linux-${{ env.BUILD_TYPE }} ${{ steps.dependencies.outputs.cmakeArgs }}
87+
# Ensure ccache uses the workspace directory shared with the host
88+
export CCACHE_DIR="$GITHUB_WORKSPACE/.ccache"
89+
mkdir -p "$CCACHE_DIR"
90+
91+
cmake --preset linux-${{ env.BUILD_TYPE }} ${{ steps.dependencies.outputs.cmakeArgs }} -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
6892
cmake --build --preset linux-${{ env.BUILD_TYPE }}
6993
env:
7094
BUILD_TYPE: ${{ github.event_name == 'pull_request' && 'debug' || 'release' }}
95+
CCACHE_DIR: ${{ github.workspace }}/.ccache
7196

7297
- name: 🏃 Perform CodeQL Analysis
7398
uses: github/codeql-action/analyze@v4.37.9
@@ -80,8 +105,16 @@ jobs:
80105
uses: advanced-security/filter-sarif@v1
81106
with:
82107
patterns: |
83-
-**/dependencies/**
84-
-**/moc_*.cpp
108+
-dependencies/**
109+
-/**/dependencies/**
110+
-moc_*.cpp
111+
-/**/moc_*.cpp
112+
-build/**
113+
-/**/build/**
114+
-*.pb.cc
115+
-/**/*.pb.cc
116+
-*.pb.h
117+
-/**/*.pb.h
85118
input: sarif-results/${{ matrix.language }}.sarif
86119
output: sarif-results/${{ matrix.language }}.sarif
87120

@@ -95,4 +128,4 @@ jobs:
95128
with:
96129
name: ${{ matrix.language }}.sarif
97130
path: sarif-results
98-
retention-days: 1
131+
retention-days: 1

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4949
- macOS bundle - Code signing identity is configurable via `MACOS_CODESIGN_IDENTITY` ('-' = ad-hoc). A stable identity keeps the macOS privacy permissions (e.g. Screen Recording) across rebuilds.
5050
- Housekeeping - GitHub builds
5151
- Script to validate translations files for common malformed placeholder/template tokens that may break the i18n parser
52+
- Update CodeQL runs to exclude external code, plus addressed CodeQL findings
5253

5354
## [2.2.1](https://github.com/hyperion-project/hyperion.ng/releases/tag/2.2.1) - 2026-04-06
5455

‎assets/firmware/arduino/network_bridge/udpraw_serialadalight.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
#
1717
# SPDX-License-Identifier: BSD-3-Clause
1818

19+
from __future__ import division
20+
1921
import sys
2022
import socket
2123
import serial
2224
import serial.threaded
2325

24-
from __future__ import division
25-
2626
class SerialToNet(serial.threaded.Protocol):
2727
"""serial->socket"""
2828

@@ -119,6 +119,11 @@ def data_received(self, data):
119119
help='local UDP port',
120120
default=2801)
121121

122+
group.add_argument(
123+
'-I', '--listen',
124+
default='0.0.0.0',
125+
help='local IP address to listen on, default: %(default)s')
126+
122127
args = parser.parse_args()
123128

124129
# connect to serial port
@@ -137,7 +142,7 @@ def data_received(self, data):
137142
if not args.quiet:
138143
sys.stderr.write(
139144
'--- UDP to Serial redirector\n'
140-
'--- listening on udp port {a.localport}\n'
145+
'--- listening on udp {a.listen}:{a.localport}\n'
141146
'--- sending to {p.name} {p.baudrate},{p.bytesize}{p.parity}{p.stopbits}\n'
142147
'--- type Ctrl-C / BREAK to quit\n'.format(p=ser, a=args))
143148

@@ -153,7 +158,7 @@ def data_received(self, data):
153158

154159
srv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
155160
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
156-
srv.bind(('0.0.0.0', args.localport))
161+
srv.bind((args.listen, args.localport))
157162

158163
try:
159164
while True:

‎assets/webconfig/js/ui_utils.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,13 +1552,13 @@ function isValidIPv6(value) {
15521552

15531553
function isValidHostname(value) {
15541554
return !!(value.match(
1555-
'^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])(.([a-zA-Z0-9]|[_a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]))*$'
1555+
/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.\w([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
15561556
));
15571557
}
15581558

15591559
function isValidServicename(value) {
15601560
return !!(value.match(
1561-
'^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9 -]{0,61}[a-zA-Z0-9])(.([a-zA-Z0-9]|[_a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]))*$'
1561+
/^[a-zA-Z0-9]([a-zA-Z0-9 -]{0,61}[a-zA-Z0-9])?(\.\w([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
15621562
));
15631563
}
15641564

‎assets/webconfig/tools/scan_i18n.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
from __future__ import annotations
2424
import re
25-
import os
2625
import json
2726
from pathlib import Path
2827
from typing import List, Dict, Any

‎effects/mood-blobs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# Calculate the color data
3535
baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
3636
if colorRandom:
37-
baseHsv = (random(), baseHsv[1], baseHsv[2])
37+
baseHsv = (random(), baseHsv[1], baseHsv[2]) # NOSONAR
3838

3939
colorData = bytearray()
4040
for i in range(hyperion.ledCount):

‎effects/pacman.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ def shift_led(led_data, increment, limit, light_pos=None):
8686
ledData = ledDataEscape
8787
shift_led(ledData, increment, hyperion.ledCount)
8888

89-
random = randint(10,hyperion.ledCount)
89+
random_pos = randint(10, hyperion.ledCount) # NOSONAR
9090

9191
# escape mode + power pellet
92-
s = slice(3*random, 3*random+3)
93-
shift_led(ledData, increment, hyperion.ledCount - random, s)
92+
s = slice(3 * random_pos, 3 * random_pos + 3)
93+
shift_led(ledData, increment, hyperion.ledCount - random_pos, s)
9494

9595
# chase mode
96-
shift = 3*(hyperion.ledCount - random)
97-
ledData = ledDataChase[shift:]+ledDataChase[:shift]
98-
shift_led(ledData, -increment, 2*hyperion.ledCount-random)
96+
shift = 3 * (hyperion.ledCount - random_pos)
97+
ledData = ledDataChase[shift:] + ledDataChase[:shift]
98+
shift_led(ledData, -increment, 2 * hyperion.ledCount - random_pos)
9999
time.sleep(sleepTime)
100100

‎effects/random.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import hyperion, time, colorsys, random, math
1+
import hyperion, time, colorsys, math, importlib
2+
3+
_stdlib_random = importlib.import_module('random')
4+
random = _stdlib_random.random
5+
randrange = _stdlib_random.randrange
26

37
# get args
48
sleepTime = float(hyperion.args.get('speed', 1.0))/1000.0
@@ -23,8 +27,8 @@
2327
ledDataBuf[i] = ledData[i]
2428

2529
for i in range(hyperion.ledCount):
26-
if random.randrange(10) == 1:
27-
rgb = colorsys.hsv_to_rgb(random.random(), saturation, random.random())
30+
if randrange(10) == 1:
31+
rgb = colorsys.hsv_to_rgb(random(), saturation, random())
2832
ledData[i*3 ] = int(255*rgb[0])
2933
ledData[i*3+1] = int(255*rgb[1])
3034
ledData[i*3+2] = int(255*rgb[2])

‎effects/sparks.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import hyperion, time, colorsys, random
1+
import hyperion, time, colorsys
2+
from random import random
23

34
# Get the parameters
45
rotationTime = float(hyperion.args.get('rotation-time', 3.0))
@@ -23,10 +24,10 @@
2324
while not hyperion.abort():
2425
ledData[:] = bytearray(3*hyperion.ledCount)
2526
for i in range(hyperion.ledCount):
26-
if random.random() < 0.005:
27+
if random() < 0.005: # NOSONAR
2728

2829
if randomColor:
29-
rgb = colorsys.hsv_to_rgb(random.random(), saturation, brightness)
30+
rgb = colorsys.hsv_to_rgb(random(), saturation, brightness) # NOSONAR
3031
for n in range(3):
3132
color[n] = int(rgb[n]*255)
3233

0 commit comments

Comments
 (0)