diff --git a/README.md b/README.md index 073c696..9061cea 100644 --- a/README.md +++ b/README.md @@ -332,8 +332,8 @@ If you find one — please report it 🙂 ## Static Analysis (Codacy / cppcheck) -- Run `scripts/cppcheck.sh` locally or in Codacy. It invokes `cppcheck` with `--library=std.cfg --check-config --enable=all --std=c99 --inline-suppr --suppress=missingIncludeSystem` and includes: +- Run `scripts/cppcheck.sh` locally or in Codacy. It invokes `cppcheck` with `--library=std.cfg --check-config --enable=all --std=c99 --inline-suppr` and includes: - `$PS2SDK/ee/include`, `$PS2SDK/iop/include`, `$PS2SDK/common/include` (defaulting to `/usr/local/ps2dev/ps2sdk`) - Project headers under `include/` - Analysis-only PS2SDK shims under `tools/codacy_shims/ps2sdk/` and minimal standard-library shims under `tools/codacy_shims/stdlib/` to avoid “missing include” findings when the real SDK or libc headers are unavailable -- If Codacy’s Cppcheck runner cannot see the PS2SDK headers, configure it to load `cppcheck-suppressions.txt` (e.g., `--suppressions-list=cppcheck-suppressions.txt`) to silence environment-only `missingInclude` / `missingIncludeSystem` noise without changing real includes. +- If Codacy’s Cppcheck runner cannot see the PS2SDK headers, point it at the shim headers under `tools/codacy_shims/` to avoid missing-include noise without masking real issues. diff --git a/mk_kelf.sh b/mk_kelf.sh index 07336d4..db7caee 100644 --- a/mk_kelf.sh +++ b/mk_kelf.sh @@ -3,6 +3,8 @@ make banner DATE=$(date "+%d-%m-%Y") SHA8=$(git rev-parse --short HEAD) +: "${DATE:?DATE is unset or empty}" +: "${SHA8:?SHA8 is unset or empty}" TARGET="PS2BBL_KELF-[$DATE]-[$SHA8]" : "${TARGET:?TARGET not set}" @@ -53,5 +55,6 @@ if [ "$TARGET" = "/" ]; then exit 1 fi +: "${TARGET:?TARGET is unset or empty}" rm -rf -- "${TARGET:?}/" echo "done!" diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index 7353a6a..7d970ba 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -23,9 +23,6 @@ exec cppcheck \ --enable=all \ --std=c99 \ --inline-suppr \ - --suppressions-list="${PROJECT_ROOT}/cppcheck-suppressions.txt" \ - --suppress=missingIncludeSystem \ - --suppress=missingInclude \ "${INCLUDE_PATHS[@]}" \ "${PROJECT_ROOT}/src" \ "${PROJECT_ROOT}/include" diff --git a/src/OSDHistory.c b/src/OSDHistory.c index 710323d..fc28211 100644 --- a/src/OSDHistory.c +++ b/src/OSDHistory.c @@ -129,10 +129,6 @@ int LoadHistoryFile(int port) fd = open(fullpath, O_RDONLY); result = 0; if (fd >= 0) { - /* Flawfinder: ignore (bounded read into fixed-size HistoryEntries buffer) */ - // cppcheck-suppress readBufferSize - // cppcheck-suppress bufferAccessOutOfBounds - // Use bounded read helper for Codacy CWE-120/CWE-20 compliance. ssize_t r = safe_read_fully_bin(fd, HistoryEntries, HISTORY_SIZE); if (r != (ssize_t)HISTORY_SIZE) result = -EIO; diff --git a/src/util_safeio.c b/src/util_safeio.c index a506d5d..f476f8c 100644 --- a/src/util_safeio.c +++ b/src/util_safeio.c @@ -1,11 +1,6 @@ #include "util_safeio.h" -#ifdef __CPPCHECK__ -typedef long ssize_t; -extern ssize_t read(int, void *, unsigned int); -#else #include -#endif /* Centralized bounded read helpers to address Codacy CWE-120/CWE-20 findings. */ @@ -15,42 +10,26 @@ static ssize_t safe_read_loop(int fd, char *buf, size_t buf_sz, int nul_terminat return -1; } -#ifdef __CPPCHECK__ - /* Cppcheck-only: avoid false-positive CWE-120 on bounded read loops. */ - size_t max_read = buf_sz; - if (nul_terminate) { - if (buf_sz == 1) { - buf[0] = '\0'; - return 0; - } - max_read = buf_sz - 1; - } - ssize_t r = read(fd, buf, (unsigned int)max_read); - if (r < 0) { - return r; + if (nul_terminate && buf_sz == 1) { + buf[0] = '\0'; + return 0; } + + size_t max_payload = buf_sz; if (nul_terminate) { - size_t term_at = ((size_t)r < buf_sz) ? (size_t)r : (buf_sz - 1); - buf[term_at] = '\0'; + max_payload = buf_sz - 1; } - return r; -#else - size_t offset = 0; - while (offset < buf_sz) { - size_t max_read = buf_sz - offset; - if (nul_terminate) { - if (max_read <= 1) { - break; // Leave space for the terminator. - } - max_read -= 1; + size_t offset = 0; + while (offset < max_payload) { + size_t to_read = max_payload - offset; + ssize_t r = read(fd, buf + offset, to_read); + if (r < 0) { + return -1; } - - ssize_t r = read(fd, buf + offset, max_read); - if (r <= 0) { + if (r == 0) { break; } - offset += (size_t)r; } @@ -59,7 +38,6 @@ static ssize_t safe_read_loop(int fd, char *buf, size_t buf_sz, int nul_terminat } return (ssize_t)offset; -#endif } ssize_t safe_read_once_nt(int fd, char *buf, size_t buf_sz)