Skip to content

Commit 6aafa7b

Browse files
authored
Update Code Scanning (#4)
1 parent 7e658cf commit 6aafa7b

File tree

9 files changed

+140
-101
lines changed

9 files changed

+140
-101
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/msvc-code-analysis-action@v0.1.1
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 }}

.github/workflows/download-cache.yml

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: powershell
13+
run: |
14+
echo "VCPKG_ROOT=${env:VCPKG_INSTALLATION_ROOT}" | Out-File -FilePath $env:GITHUB_ENV -Append
15+
echo "VCPKG_CACHE=${env:LOCALAPPDATA}\vcpkg\archives" | Out-File -FilePath $env:GITHUB_ENV -Append
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 }}

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
## Author Francois Michaut
55
##
66
## Started on Sun Aug 28 19:26:51 2022 Francois Michaut
7-
## Last update Mon Aug 4 23:34:08 2025 Francois Michaut
7+
## Last update Tue Aug 5 19:07:23 2025 Francois Michaut
88
##
99
## CMakeLists.txt : CMake to build the CppSockets library
1010
##
1111

1212
cmake_minimum_required (VERSION 3.15)
13-
set(CMAKE_CXX_STANDARD 17)
13+
set(CMAKE_CXX_STANDARD 20)
1414
set(CMAKE_CXX_STANDARD_REQUIRED True)
1515
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1616

include/CppSockets/Certificate.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Fri Aug 1 09:50:33 2025 Francois Michaut
7-
** Last update Mon Aug 4 23:45:31 2025 Francois Michaut
7+
** Last update Tue Aug 5 19:08:13 2025 Francois Michaut
88
**
99
** Certificate.hpp : Classes to create and manage Certificates
1010
*/
@@ -18,12 +18,6 @@
1818
#include <cstdint>
1919
#include <filesystem>
2020

21-
#if __cplusplus < 202002L
22-
namespace std {
23-
using u8string = basic_string<unsigned char>; // NOLINT(cert-dcl58-cpp)
24-
}
25-
#endif
26-
2721
namespace CppSockets {
2822
class x509NameEntry;
2923

@@ -164,8 +158,8 @@ namespace CppSockets {
164158
// TODO: Get methods
165159

166160
// TODO: Provide overloads for hardcoded time
167-
void set_not_before(int offset_day, std::int64_t offset_sec, time_t *in_tm);
168-
void set_not_after(int offset_day, std::int64_t offset_sec, time_t *in_tm);
161+
void set_not_before(int offset_day, std::int64_t offset_sec, time_t *in_tm = nullptr);
162+
void set_not_after(int offset_day, std::int64_t offset_sec, time_t *in_tm = nullptr);
169163

170164
void set_version(std::int64_t version);
171165
[[nodiscard]]

source/Certificate.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sat Aug 2 22:41:35 2025 Francois Michaut
7-
** Last update Tue Aug 5 13:08:40 2025 Francois Michaut
7+
** Last update Tue Aug 5 19:12:12 2025 Francois Michaut
88
**
99
** Certificate.cpp : Implementation of classes to create and manage Certificates
1010
*/
@@ -72,19 +72,19 @@ namespace CppSockets {
7272
}
7373

7474
void x509Name::add_entry(const std::string &field_name, int type, const std::u8string &data, int loc, int set) {
75-
auto ret = X509_NAME_add_entry_by_txt(m_ptr.get(), field_name.c_str(), type, data.c_str(), numeric_cast<int>(data.size()), loc, set);
75+
auto ret = X509_NAME_add_entry_by_txt(m_ptr.get(), field_name.c_str(), type, reinterpret_cast<const unsigned char *>(data.c_str()), numeric_cast<int>(data.size()), loc, set);
7676

7777
check_or_throw_openssl_error(ret);
7878
}
7979

8080
void x509Name::add_entry(const ASN1_OBJECT *obj, int type, const std::u8string &data, int loc, int set) {
81-
auto ret = X509_NAME_add_entry_by_OBJ(m_ptr.get(), obj, type, data.c_str(), numeric_cast<int>(data.size()), loc, set);
81+
auto ret = X509_NAME_add_entry_by_OBJ(m_ptr.get(), obj, type, reinterpret_cast<const unsigned char *>(data.c_str()), numeric_cast<int>(data.size()), loc, set);
8282

8383
check_or_throw_openssl_error(ret);
8484
}
8585

8686
void x509Name::add_entry(int nid, int type, const std::u8string &data, int loc, int set) {
87-
auto ret = X509_NAME_add_entry_by_NID(m_ptr.get(), nid, type, data.c_str(), numeric_cast<int>(data.size()), loc, set);
87+
auto ret = X509_NAME_add_entry_by_NID(m_ptr.get(), nid, type, reinterpret_cast<const unsigned char *>(data.c_str()), numeric_cast<int>(data.size()), loc, set);
8888

8989
check_or_throw_openssl_error(ret);
9090
}
@@ -129,19 +129,19 @@ namespace CppSockets {
129129
}
130130

131131
x509NameEntry::x509NameEntry(const std::string &name, int type, const std::u8string &data) :
132-
m_ptr(X509_NAME_ENTRY_create_by_txt(nullptr, name.c_str(), type, data.c_str(), numeric_cast<int>(data.size())))
132+
m_ptr(X509_NAME_ENTRY_create_by_txt(nullptr, name.c_str(), type, reinterpret_cast<const unsigned char *>(data.c_str()), numeric_cast<int>(data.size())))
133133
{
134134
REQUIRED_PTR(m_ptr, "X509_NAME_ENTRY")
135135
}
136136

137137
x509NameEntry::x509NameEntry(const ASN1_OBJECT *obj, int type, const std::u8string &data) :
138-
m_ptr(X509_NAME_ENTRY_create_by_OBJ(nullptr, obj, type, data.c_str(), numeric_cast<int>(data.size())))
138+
m_ptr(X509_NAME_ENTRY_create_by_OBJ(nullptr, obj, type, reinterpret_cast<const unsigned char *>(data.c_str()), numeric_cast<int>(data.size())))
139139
{
140140
REQUIRED_PTR(m_ptr, "X509_NAME_ENTRY")
141141
}
142142

143143
x509NameEntry::x509NameEntry(int nid, int type, const std::u8string &data) :
144-
m_ptr(X509_NAME_ENTRY_create_by_NID(nullptr, nid, type, data.c_str(), numeric_cast<int>(data.size())))
144+
m_ptr(X509_NAME_ENTRY_create_by_NID(nullptr, nid, type, reinterpret_cast<const unsigned char *>(data.c_str()), numeric_cast<int>(data.size())))
145145
{
146146
REQUIRED_PTR(m_ptr, "X509_NAME_ENTRY")
147147
}
@@ -157,7 +157,7 @@ namespace CppSockets {
157157
}
158158

159159
void x509NameEntry::set_data(int type, const std::u8string &data) {
160-
auto ret = X509_NAME_ENTRY_set_data(m_ptr.get(), type, data.c_str(), numeric_cast<int>(data.size()));
160+
auto ret = X509_NAME_ENTRY_set_data(m_ptr.get(), type, reinterpret_cast<const unsigned char *>(data.c_str()), numeric_cast<int>(data.size()));
161161

162162
check_or_throw_openssl_error(ret);
163163
}

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)

0 commit comments

Comments
 (0)