tool_cb_hdr: only truncate etags output when regular file#21103
Closed
tool_cb_hdr: only truncate etags output when regular file#21103
Conversation
There was a problem hiding this comment.
Pull request overview
Adjusts curl tool ETag saving behavior so --etag-save - (stdout) doesn’t fail due to truncation attempts on non-seekable streams, and adds a regression test to validate stdout output.
Changes:
- Guard ETag “truncate before write” logic so it only runs for file outputs (not stdout).
- Add new test coverage for
--etag-save -output. - Register the new test in the test data Makefile list.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/tool_cb_hdr.c |
Avoid truncating ETag output when writing to non-file streams (e.g., stdout). |
tests/data/test1619 |
New test verifying --etag-save - writes the ETag to stdout. |
tests/data/Makefile.am |
Adds test1619 to the known test list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When sending the output to stdout it cannot truncate. Add test1619 to verify --etag-save to stdout Spotted by Codex Security
4de6c0c to
590a61c
Compare
dfandrich
reviewed
Mar 26, 2026
| if(fseek(etag_save->stream, 0, SEEK_SET)) { | ||
| return CURL_WRITEFUNC_ERROR; | ||
| } | ||
| if(fseek(etag_save->stream, 0, SEEK_SET)) |
Contributor
There was a problem hiding this comment.
What happens when the new file is shorter than the old file? There will be garbage left at the end.
Member
Author
There was a problem hiding this comment.
Yes, but this code existed like this already before. And see #21109 for a fix.
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.
When sending the output to stdout it cannot truncate.
Add test1619 to verify --etag-save to stdout
Spotted by Codex Security