Skip to content

Commit 0551b42

Browse files
committed
Update Code Scanning
1 parent 7e658cf commit 0551b42

File tree

6 files changed

+127
-82
lines changed

6 files changed

+127
-82
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,13 @@ jobs:
5454
- name: Set Env
5555
shell: bash
5656
run: |
57-
echo "VCPKG_ROOT=${VCPKG_INSTALLATION_ROOT}" >> "$GITHUB_ENV"
5857
echo "BUILD_OUTPUT_DIR=${{ github.workspace }}/build" >> "$GITHUB_ENV"
5958
60-
- name: Fetch VCPKG Cache (Windows)
61-
id: fetch-vcpkg-cache
59+
- name: VCPKG Install (Windows)
6260
if: runner.os == 'Windows'
63-
uses: actions/cache/restore@v4
61+
uses: ./.github/workflows/windows-vcpkg
6462
with:
65-
key: ${{ runner.os }}-${{ matrix.build_type }}-${{ hashFiles('vcpkg.json') }}
66-
path: ${{ env.VCPKG_ROOT }}
67-
68-
- name: Install OpenSSL (Windows)
69-
if: runner.os == 'Windows'
70-
shell: powershell
71-
run: |
72-
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
73-
vcpkg install
74-
75-
- name: Always Save VCPKG Cache (Windows)
76-
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'
77-
uses: actions/cache/save@v4
78-
with:
79-
key: ${{ steps.fetch-vcpkg-cache.outputs.cache-primary-key }}
80-
path: ${{ env.VCPKG_ROOT }}
63+
key: ${{ runner.os }}-${{ matrix.build_type }}
8164

8265
- name: Configure CMake
8366
# Configure CMake in a 'build' subdirectory.

.github/workflows/code_scanning.yml

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
# Initializes the CodeQL tools for scanning.
3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@v2
33+
uses: github/codeql-action/init@v3
3434
with:
3535
languages: 'c-cpp'
3636
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -44,20 +44,10 @@ jobs:
4444
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
4545
# If this step fails, then you should remove it and run the build manually (see below)
4646
- name: Autobuild
47-
uses: github/codeql-action/autobuild@v2
48-
49-
# ℹ️ Command-line programs to run using the OS shell.
50-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
51-
52-
# If the Autobuild fails above, remove it and uncomment the following three lines.
53-
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
54-
55-
# - run: |
56-
# echo "Run, Build Application using script"
57-
# ./location_of_script_within_repo/buildscript.sh
47+
uses: github/codeql-action/autobuild@v3
5848

5949
- name: Perform CodeQL Analysis
60-
uses: github/codeql-action/analyze@v2
50+
uses: github/codeql-action/analyze@v3
6151
with:
6252
category: "/language:c-cpp"
6353

@@ -73,53 +63,66 @@ jobs:
7363
uses: actions/checkout@v3
7464

7565
- name: flawfinder_scan
76-
uses: david-a-wheeler/flawfinder@8e4a779ad59dbfaee5da586aa9210853b701959c
66+
uses: david-a-wheeler/flawfinder@2.0.19
7767
with:
7868
arguments: '--sarif ./'
7969
output: 'flawfinder_results.sarif'
8070

8171
- name: Upload analysis results to GitHub Security tab
82-
uses: github/codeql-action/upload-sarif@v2
72+
uses: github/codeql-action/upload-sarif@v3
8373
with:
8474
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
8575

86-
# microsoft-analyze:
87-
# permissions:
88-
# contents: read # for actions/checkout to fetch code
89-
# security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
90-
# actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
91-
# name: Microsoft Analyze
92-
# runs-on: windows-latest
93-
94-
# steps:
95-
# - name: Checkout repository
96-
# uses: actions/checkout@v3
97-
98-
# - name: Configure CMake
99-
# run: cmake -B ./build
100-
101-
# # Build is not required unless generated source files are used
102-
# # - name: Build CMake
103-
# # run: cmake --build ./build
104-
105-
# - name: Initialize MSVC Code Analysis
106-
# uses: microsoft/msvc-code-analysis-action@04825f6d9e00f87422d6bf04e1a38b1f3ed60d99
107-
# # Provide a unique ID to access the sarif output path
108-
# id: run-analysis
109-
# with:
110-
# cmakeBuildDirectory: ${{ env.build }}
111-
# # Ruleset file that will determine what checks will be run
112-
# ruleset: NativeRecommendedRules.ruleset
113-
114-
# # Upload SARIF file to GitHub Code Scanning Alerts
115-
# - name: Upload SARIF to GitHub
116-
# uses: github/codeql-action/upload-sarif@v2
117-
# with:
118-
# sarif_file: ${{ steps.run-analysis.outputs.sarif }}
119-
120-
# # Upload SARIF file as an Artifact to download and view
121-
# # - name: Upload SARIF as an Artifact
122-
# # uses: actions/upload-artifact@v3
123-
# # with:
124-
# # name: sarif-file
125-
# # path: ${{ steps.run-analysis.outputs.sarif }}
76+
microsoft-analyze:
77+
permissions:
78+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
79+
contents: read # for actions/checkout to fetch code
80+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
81+
name: Microsoft Analyze
82+
runs-on: windows-latest
83+
84+
env:
85+
# Path to the CMake build directory.
86+
build: '${{ github.workspace }}/build'
87+
config: 'Debug'
88+
89+
steps:
90+
- name: Checkout repository
91+
uses: actions/checkout@v3
92+
93+
- name: VCPKG Install (Windows)
94+
uses: ./.github/workflows/windows-vcpkg
95+
with:
96+
key: ${{ runner.os }}-${{ env.config }}
97+
98+
- name: Configure CMake
99+
run: cmake -B ${{ env.build }} -DCMAKE_BUILD_TYPE=${{ env.config }}
100+
101+
# Build is not required unless generated source files are used
102+
# - name: Build CMake
103+
# run: cmake --build ${{ env.build }} --config ${{ env.config }}
104+
105+
- name: Run MSVC Code Analysis
106+
uses: microsoft/[email protected]
107+
# Provide a unique ID to access the sarif output path
108+
id: run-analysis
109+
with:
110+
cmakeBuildDirectory: ${{ env.build }}
111+
buildConfiguration: ${{ env.config }}
112+
# Ruleset file that will determine what checks will be run
113+
ruleset: NativeRecommendedRules.ruleset
114+
# Paths to ignore analysis of CMake targets and includes
115+
# ignoredPaths: ${{ github.workspace }}/dependencies;${{ github.workspace }}/test
116+
117+
# Upload SARIF file to GitHub Code Scanning Alerts
118+
- name: Upload SARIF to GitHub
119+
uses: github/codeql-action/upload-sarif@v3
120+
with:
121+
sarif_file: ${{ steps.run-analysis.outputs.sarif }}
122+
123+
# # Upload SARIF file as an Artifact to download and view
124+
# - name: Upload SARIF as an Artifact
125+
# uses: actions/upload-artifact@v4
126+
# with:
127+
# name: sarif-file
128+
# path: ${{ steps.run-analysis.outputs.sarif }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
cache-key:
5+
description: 'The key of the cache to retrieve'
6+
required: true
7+
8+
jobs:
9+
download_and_upload_cache:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Restore cache
13+
uses: actions/cache@v4
14+
with:
15+
path: ./cache
16+
key: ${{ inputs.cache-key }}
17+
18+
- name: Upload cached data as artifact
19+
uses: actions/upload-artifact@v3
20+
with:
21+
name: cached-data-artifact
22+
path: ./cache
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Windows VCPKG
2+
3+
inputs:
4+
key:
5+
required: true
6+
type: string
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Set Env
12+
shell: bash
13+
run: |
14+
echo "VCPKG_ROOT=${VCPKG_INSTALLATION_ROOT}" >> "$GITHUB_ENV"
15+
echo "VCPKG_CACHE=${LOCAL_APP_DATA}\vcpkg\archives" >> "$GITHUB_ENV"
16+
17+
- name: Fetch VCPKG Cache (Windows)
18+
id: fetch-vcpkg-cache
19+
if: runner.os == 'Windows'
20+
uses: actions/cache/restore@v4
21+
with:
22+
key: ${{ inputs.key }}-vcpkg-${{ hashFiles('vcpkg.json') }}
23+
path: ${{ env.VCPKG_CACHE }}
24+
25+
- name: VCPKG Install (Windows)
26+
if: runner.os == 'Windows'
27+
shell: powershell
28+
run: |
29+
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
30+
vcpkg install --debug
31+
32+
- name: Always Save VCPKG Cache (Windows)
33+
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'
34+
uses: actions/cache/save@v4
35+
with:
36+
key: ${{ steps.fetch-vcpkg-cache.outputs.cache-primary-key }}
37+
path: ${{ env.VCPKG_CACHE }}

source/Socket.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sat Jan 15 01:27:40 2022 Francois Michaut
7-
** Last update Tue Aug 5 00:04:25 2025 Francois Michaut
7+
** Last update Tue Aug 5 14:46:12 2025 Francois Michaut
88
**
99
** Socket.cpp : Protable C++ socket class implementation
1010
*/
@@ -46,7 +46,7 @@ namespace CppSockets {
4646
{
4747
socklen_t len = sizeof(int);
4848

49-
Socket::getsockopt(sockfd, SOL_SOCKET, SO_TYPE, (SockOptType *)&m_type, &len);
49+
Socket::getsockopt(sockfd, SOL_SOCKET, SO_TYPE, reinterpret_cast<SockOptType *>(&m_type), &len);
5050
#ifdef OS_LINUX
5151
Socket::getsockopt(sockfd, SOL_SOCKET, SO_DOMAIN, &m_domain, &len);
5252
Socket::getsockopt(sockfd, SOL_SOCKET, SO_PROTOCOL, &m_protocol, &len);
@@ -128,7 +128,7 @@ namespace CppSockets {
128128
std::size_t nb = 1;
129129

130130
while (nb != 0 && (len == -1 || total < len)) {
131-
nb = this->read(buff.data(), BUFF_SIZE);
131+
nb = this->read(buff.data(), buff.size());
132132
if (nb > 0) {
133133
res << std::string(buff.data(), nb);
134134
}
@@ -168,7 +168,7 @@ namespace CppSockets {
168168
auto Socket::set_reuseaddr(bool value) -> int {
169169
int val = static_cast<int>(value);
170170

171-
return this->setsockopt(SOL_SOCKET, SO_REUSEADDR, (SockOptType *)&val, sizeof(val));
171+
return this->setsockopt(SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<SockOptType *>(&val), sizeof(val));
172172
}
173173

174174
auto Socket::getsockopt(int level, int optname, SockOptType *optval, socklen_t *optlen) -> int { // NOLINT(readability-make-member-function-const)

source/TlsSocket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Wed Sep 14 21:04:42 2022 Francois Michaut
7-
** Last update Sun Aug 3 22:18:06 2025 Francois Michaut
7+
** Last update Tue Aug 5 13:49:19 2025 Francois Michaut
88
**
99
** SecureSocket.cpp : TLS socket wrapper implementation
1010
*/
@@ -154,13 +154,13 @@ namespace CppSockets {
154154
std::size_t nb = 0;
155155
std::size_t total;
156156

157-
if (SSL_peek(m_ssl.get(), buff.data(), BUFF_SIZE) <= 0) {
157+
if (SSL_peek(m_ssl.get(), buff.data(), buff.size()) <= 0) {
158158
set_connected(false); // TODO: we should replace this with check_for_error
159159
}
160160
check_for_error("Failed to read from socket", 1); // Do not raise an error if peek failed
161161
total = SSL_pending(m_ssl.get());
162162
while (total != 0 && len != 0) {
163-
nb = this->read(buff.data(), (BUFF_SIZE > len ? len : BUFF_SIZE));
163+
nb = this->read(buff.data(), (buff.size() > len ? len : buff.size()));
164164
res << std::string(buff.data(), nb);
165165
total -= nb;
166166
if (len != -1)

0 commit comments

Comments
 (0)