fix(tfile): read_tfile() returns 0 on error instead of 1 (F-23, #99)#158
Merged
adequatelimited merged 1 commit intoaudit-fixesfrom Apr 13, 2026
Merged
Conversation
…1-record read read_tfile() returns size_t but previously returned VERROR (==1) on fopen() failure, which is indistinguishable from a successful read of one trailer. Callers that check `!= 1` or `<= 0` silently accepted the error as success and continued with uninitialized buffer data on the consensus-critical paths (ng_val, contention, send_found). Return 0 on error instead. All existing callers already check `!= 1`, `<= 0`, or `!= NTFTX` which correctly detect 0. Also wire up the pre-existing TODO in send_found() to check count != NTFTX and exit the forked child on incomplete read. Unit test in src/test/tfile-read-error.c covers the three cases: missing file, partial read, and seek-past-EOF.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #99 (F-23).
`read_tfile()` returns `size_t` but previously returned `VERROR` (==1) on `fopen()` failure. `1` is also a valid count for "one trailer read successfully." Callers that check `!= 1` or `<= 0` silently treated the error as success and proceeded with uninitialized buffer data on consensus-critical paths (`ng_val`, `contention`, `send_found`).
This change returns `0` on error. All existing callers already check `!= 1`, `<= 0`, or `!= NTFTX`, which correctly detect `0`.
Also wires up the pre-existing TODO in `send_found()` to check `count != NTFTX` and exit the forked child on incomplete read.
Test plan