Skip to content

tool_cb_hdr: only truncate etags output when regular file#21103

Closed
bagder wants to merge 3 commits intomasterfrom
bagder/etag-save-stdout
Closed

tool_cb_hdr: only truncate etags output when regular file#21103
bagder wants to merge 3 commits intomasterfrom
bagder/etag-save-stdout

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented Mar 26, 2026

When sending the output to stdout it cannot truncate.

Add test1619 to verify --etag-save to stdout

Spotted by Codex Security

@github-actions github-actions bot added the tests label Mar 26, 2026
@bagder bagder marked this pull request as ready for review March 26, 2026 13:57
@bagder bagder requested a review from Copilot March 26, 2026 13:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

bagder added 2 commits March 26, 2026 22:42
When sending the output to stdout it cannot truncate.

Add test1619 to verify --etag-save to stdout

Spotted by Codex Security
@bagder bagder force-pushed the bagder/etag-save-stdout branch from 4de6c0c to 590a61c Compare March 26, 2026 21:59
@bagder bagder closed this in d63432d Mar 26, 2026
@bagder bagder deleted the bagder/etag-save-stdout branch March 26, 2026 22:39
if(fseek(etag_save->stream, 0, SEEK_SET)) {
return CURL_WRITEFUNC_ERROR;
}
if(fseek(etag_save->stream, 0, SEEK_SET))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when the new file is shorter than the old file? There will be garbage left at the end.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this code existed like this already before. And see #21109 for a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants