17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-04 22:25:45 +01:00

fix: sonar sast fixes - sonar.yml, nosonar, linux chmod modification

This commit is contained in:
jerrrrycho
2026-09-28 21:07:53 +02:00
committed by GitHub
parent 8fbb482350
commit 4137f5504a
7 changed files with 36 additions and 11 deletions

View File

@@ -70,7 +70,9 @@ jobs:
pull-requests: read # verify PR head sha via the API pull-requests: read # verify PR head sha via the API
env: env:
BUILD_WRAPPER_OUT_DIR: bw-output BUILD_WRAPPER_OUT_DIR: bw-output
SONAR_EXCLUSIONS: betterRenderer/**,ref/**,imgui/**,stb/**,build/**,bw-output/** # .trusted/ holds the checkout of master used to restore the scanner config;
# it is not part of the analysed change.
SONAR_EXCLUSIONS: betterRenderer/**,ref/**,imgui/**,stb/**,build/**,bw-output/**,.trusted/**
SONAR_SCANNER_JAVA_OPTS: -Xmx5g SONAR_SCANNER_JAVA_OPTS: -Xmx5g
steps: steps:
- name: Post pending status - name: Post pending status
@@ -102,12 +104,26 @@ jobs:
- name: Unpack analysis input - name: Unpack analysis input
run: | run: |
set -euo pipefail set -euo pipefail
# The archive holds the whole PR workspace and is unpacked over this one,
# .trusted/ included. Move the trusted config out of reach first, or a PR
# carrying its own .trusted/sonar-project.properties would have it planted
# here and restored below as if it came from master.
if [ -f "$GITHUB_WORKSPACE/.trusted/sonar-project.properties" ]; then
cp "$GITHUB_WORKSPACE/.trusted/sonar-project.properties" /tmp/trusted-sonar-project.properties
fi
# Nothing may be written outside the workspace: reject absolute members and
# any member reaching through a parent directory before unpacking anything.
tar -tzf /tmp/sonar-input/workspace.tar.gz > /tmp/archive-members.txt
if grep -qE '^/|(^|/)[.][.](/|$)' /tmp/archive-members.txt; then
echo "::error::archive contains paths outside the workspace"
exit 1
fi
tar -xzf /tmp/sonar-input/workspace.tar.gz -C "$GITHUB_WORKSPACE" tar -xzf /tmp/sonar-input/workspace.tar.gz -C "$GITHUB_WORKSPACE"
# Strip PR-controlled scanner configuration, restore the trusted one. # Strip PR-controlled scanner configuration, restore the trusted one.
rm -f "$GITHUB_WORKSPACE/sonar-project.properties" \ rm -f "$GITHUB_WORKSPACE/sonar-project.properties" \
"$GITHUB_WORKSPACE/.sonarcloud.properties" "$GITHUB_WORKSPACE/.sonarcloud.properties"
if [ -f "$GITHUB_WORKSPACE/.trusted/sonar-project.properties" ]; then if [ -f /tmp/trusted-sonar-project.properties ]; then
cp "$GITHUB_WORKSPACE/.trusted/sonar-project.properties" "$GITHUB_WORKSPACE/" cp /tmp/trusted-sonar-project.properties "$GITHUB_WORKSPACE/sonar-project.properties"
fi fi
- name: Resolve and verify PR metadata - name: Resolve and verify PR metadata

View File

@@ -1105,7 +1105,7 @@ void eu07_application::init_files()
#elif __unix__ #elif __unix__
unlink("log.txt"); unlink("log.txt");
unlink("errors.txt"); unlink("errors.txt");
mkdir("logs", 0755); mkdir("logs", 0750);
#endif #endif
} }
namespace fs = std::filesystem; namespace fs = std::filesystem;

View File

@@ -6,7 +6,9 @@ sonar.sources=.
sonar.sourceEncoding=UTF-8 sonar.sourceEncoding=UTF-8
# Exclusions # Exclusions
sonar.exclusions=betterRenderer/**,ref/**,imgui/**,stb/**,build/**,bw-output/** # .trusted/ is the copy of master the analysis workflow checks out to restore its
# own configuration; analysing it would duplicate every file of the base branch.
sonar.exclusions=betterRenderer/**,ref/**,imgui/**,stb/**,build/**,bw-output/**,.trusted/**
# Excluding all files from coverage making the gate skip that # Excluding all files from coverage making the gate skip that
# instead of failing it. # instead of failing it.

View File

@@ -38,8 +38,14 @@ struct global_settings {
bool shiftState{ false }; //m7todo: brzydko bool shiftState{ false }; //m7todo: brzydko
bool ctrlState{ false }; bool ctrlState{ false };
bool altState{ false }; bool altState{ false };
std::mt19937 random_engine; // Simulation randomness, never used for anything security related: no keys, tokens or
std::mt19937 local_random_engine; // credentials come out of these. Reproducibility is a requirement here, which is why both
// are plain mt19937 -- the run's seed can be written down and passed on, and it travels in
// server_hello so that every client in a session replays the same sequence. A generator
// that cannot be seeded to a known state would break both of those.
std::mt19937 random_engine; // NOSONAR shared run seed, kept in sync across the network
std::mt19937 local_random_engine; // NOSONAR re-seeded from a true random source in init_modes,
// drives purely local cosmetics (sound pitch, editor placement)
bool ready_to_load{ false }; bool ready_to_load{ false };
std::time_t starting_timestamp = 0; // starting time, in local timezone std::time_t starting_timestamp = 0; // starting time, in local timezone
uint32_t random_seed = 0; uint32_t random_seed = 0;

View File

@@ -399,7 +399,7 @@ void uart_input::poll()
char buf[buffer.size() * 3 + 1]; char buf[buffer.size() * 3 + 1];
size_t pos = 0; size_t pos = 0;
for (uint8_t b : buffer) for (uint8_t b : buffer)
pos += sprintf(&buf[pos], "%02X ", b); pos += snprintf(&buf[pos], sizeof(buf) - pos, "%02X ", b);
WriteLog("uart: rx: " + std::string(buf)); WriteLog("uart: rx: " + std::string(buf));
} }
@@ -635,7 +635,7 @@ void uart_input::poll()
buf[ buffer.size() * 3 ] = 0; buf[ buffer.size() * 3 ] = 0;
size_t pos = 0; size_t pos = 0;
for (uint8_t b : buffer) for (uint8_t b : buffer)
pos += sprintf(&buf[pos], "%02X ", b); pos += snprintf(&buf[pos], sizeof(buf) - pos, "%02X ", b);
WriteLog("uart: tx: " + std::string(buf)); WriteLog("uart: tx: " + std::string(buf));
} }

View File

@@ -1901,7 +1901,7 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche,
#ifdef _WIN32 #ifdef _WIN32
CreateDirectory( "physicslog", nullptr); CreateDirectory( "physicslog", nullptr);
#elif __unix__ #elif __unix__
mkdir( "physicslog", 0744 ); mkdir( "physicslog", 0740 );
#endif #endif
LogFile.open( std::string( "physicslog/" + VehicleName + ".dat" ), LogFile.open( std::string( "physicslog/" + VehicleName + ".dat" ),
std::ios::in | std::ios::out | std::ios::trunc ); std::ios::in | std::ios::out | std::ios::trunc );

View File

@@ -3024,7 +3024,8 @@ TDynamicObject::update_load_offset() {
void void
TDynamicObject::shuffle_load_order() { TDynamicObject::shuffle_load_order() {
std::shuffle( std::begin( SectionLoadOrder ), std::end( SectionLoadOrder ), Global.random_engine ); // order of visible load chunks, nothing security related -- see the engines in Globals.h
std::shuffle( std::begin( SectionLoadOrder ), std::end( SectionLoadOrder ), Global.random_engine ); // NOSONAR
// shift chunks assigned to corridors to the end of the list, so they show up last // shift chunks assigned to corridors to the end of the list, so they show up last
std::stable_partition( std::stable_partition(
std::begin( SectionLoadOrder ), std::end( SectionLoadOrder ), std::begin( SectionLoadOrder ), std::end( SectionLoadOrder ),