Skip to content

Audit fixes batch 6: system() replacements, refresh_ipl fix, external script checks#141

Merged
adequatelimited merged 8 commits intomasterfrom
audit-fixes
Apr 6, 2026
Merged

Audit fixes batch 6: system() replacements, refresh_ipl fix, external script checks#141
adequatelimited merged 8 commits intomasterfrom
audit-fixes

Conversation

@adequatelimited
Copy link
Copy Markdown
Collaborator

Summary

Sixth batch of audit remediation. Eliminates all shell-spawning system() calls for file operations, fixes a silently broken peer-help mechanism, and adds error logging to external script hooks.

Changes

Testing

Closes #114

refresh_ipl() performed two sequential read_tfile() calls into
tx.buffer. The first read's output was immediately cleared and
overwritten by the second, but count from the first read was used
to set the packet length — making the OP_FOUND proof malformed
(length from read A, buffer content from read B). Receiving peers
would reject the mismatched proof, silently breaking the background
peer-help mechanism.

Replaced with a single read_tfile() matching send_found()'s pattern,
including the NTFTX-1 offset for correct inclusive range. Added
count != NTFTX check to skip the send on short/failed reads.
Added TODO comment in send_found() for the same check.
…-read

[F-26] fix(network): remove dead double-read in refresh_ipl() OP_FOUND proof
Closes #108

Replaced shell-spawning system() calls in syncup() and b_update()
with native C equivalents using fcopy(), mkdir_p(), rename(),
fappend(), and rmdir_r(). The original calls had no return-value
checks, so failures (disk full, permissions, missing files) were
silently ignored, potentially leaving the node with corrupted state.

Changes:
- syncup() backup: mkdir -p/cp -> mkdir_p()/fcopy() with error check
- syncup() restore: mv/rm -> rename()/rmdir_r() with error logging
- b_update() txq append: cat >> -> fappend() with error logging

New files:
- src/util.h/util.c: fappend() and rmdir_r() utilities, documented
  for future migration to the extended-c library
[F-06] fix(sync,bup): replace system() calls with native C file operations
Closes #105

send_tf() used sprintf to construct a dd shell command with a
peer-controlled skip offset, then executed it via system(). This
spawned two processes per request with no error checking, and
placed peer-controlled values into a shell command string.

Replaced with fseek64/fread/fwrite operating directly on tfile.dat.
Identical output: reads count trailers starting at offset first,
writes to temp file, sends via send_file(). Handles EOF and
errors explicitly.
[F-12] fix(network): replace system(dd) with native C in send_tf()
Closes #109

system() calls to ../update-external.sh and ../init-external.sh
had no return-value checks. A failed or erroring script was
silently ignored. Added checks and pwarn() logging on non-zero
return so failures are visible in the node log.
…ecks

[F-20] fix(bup,sync): add return-value checks on external script system() calls
@adequatelimited adequatelimited merged commit 69818ef into master Apr 6, 2026
4 of 5 checks passed
adequatelimited added a commit that referenced this pull request Apr 13, 2026
Audit fixes batch 6: system() replacements, refresh_ipl fix, external script checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment