Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions mk_kelf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -53,5 +55,6 @@ if [ "$TARGET" = "/" ]; then
exit 1
fi

: "${TARGET:?TARGET is unset or empty}"
rm -rf -- "${TARGET:?}/"
echo "done!"
3 changes: 0 additions & 3 deletions scripts/cppcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 0 additions & 4 deletions src/OSDHistory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 13 additions & 35 deletions src/util_safeio.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#include "util_safeio.h"

#ifdef __CPPCHECK__
typedef long ssize_t;
extern ssize_t read(int, void *, unsigned int);
#else
#include <unistd.h>
#endif

/* Centralized bounded read helpers to address Codacy CWE-120/CWE-20 findings. */

Expand All @@ -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;
}

Expand All @@ -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)
Expand Down