dd: don't silently swallow truncate failures#12340
Open
c-tonneslan wants to merge 1 commit into
Open
Conversation
The wrapper around set_len() was suppressing every error from the truncate step because set_len() on `/dev/null` returns EINVAL. That also hid real failures like ENOSPC (disk full) and EROFS (read-only filesystem), so dd would exit 0 while leaving stale tail bytes in the output file. Backup scripts trusting dd's exit code would then think a copy succeeded when it didn't. Only swallow InvalidInput (the kind ftruncate returns on non-regular files); everything else propagates up to the caller and dd exits non-zero. Verified that `of=/dev/null` still works. Closes uutils#9745. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
|
GNU testsuite comparison: |
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.
Closes #9745.
Output::truncatewas suppressing every error fromset_len()by calling.ok(), which the comment justified by pointing atof=/dev/null(whereftruncatereturns EINVAL). That also hid real failures like ENOSPC and EROFS, so dd would exit 0 while leaving stale tail bytes in the output file.Narrow the swallow to InvalidInput (which is what
set_lenreturns on non-regular files) and propagate everything else.of=/dev/nullstill works, real I/O errors now surface.