[Session] Truncate session file after successful write - #278
Open
iliaal wants to merge 1 commit into
Open
Conversation
The files save handler ftruncated the session file to 0 before writing, so a failed or short write returned FAILURE with the previous session data already destroyed. Write first and truncate the old tail to the new length only after the full buffer was written successfully. Sibling audit: PS_WRITE_FUNC/PS_UPDATE_FUNC callers and the read path are unaffected; the empty-write destroy path truncates identically.
iliaal
force-pushed
the
fix/session-write-truncate-84
branch
2 times, most recently
from
August 26, 2026 12:44
846773a to
f1dedf0
Compare
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.
The files session save handler truncated the session file to 0 before writing new data, so a failed or short write (RLIMIT_FSIZE with SIGXFSZ ignored, for example) made ps_files_write() return FAILURE while the previous session data was already gone. ps_files_write() now writes first and truncates to the new length only after the full buffer lands, so failed writes leave prior data intact. A regression test reproduces the loss via posix_setrlimit(POSIX_RLIMIT_FSIZE); PS_WRITE_FUNC, PS_UPDATE_TIMESTAMP_FUNC and PS_DESTROY_FUNC were audited and behave identically. Closes aph-er5.