scp: fix duplicate file header on send#1128
Open
ejohnstown wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an SCP server-side edge case where the file header could be transmitted more than once when the SCP send callback returns 0 bytes on its first invocation, and adds a regression test by allowing tests to inject a custom SCP send callback into the echoserver harness.
Changes:
- Add
scpFileHeaderSentstate to gate header emission per file (instead of relying onscpFileOffset == 0). - Avoid emitting zero-length
CHANNEL_DATAwhen the send buffer is empty, and reset SCP per-file state on source init / connection reuse paths. - Add
test_wolfSSH_SCP_SendZeroFirstregression test and enable callback injection viafunc_args.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| wolfssh/test.h | Includes wolfscp.h under WOLFSSH_SCP and extends func_args with an injectable scp_send callback. |
| wolfssh/internal.h | Adds scpFileHeaderSent to SCP state tracked on the WOLFSSH object. |
| tests/api.c | Adds a regression test ensuring a 0-byte-first send callback does not cause a duplicated SCP file header. |
| src/wolfscp.c | Uses scpFileHeaderSent to gate header sending, skips zero-length sends, and resets per-file state for reuse. |
| src/internal.c | Initializes scpFileHeaderSent during SSH session initialization. |
| examples/echoserver/echoserver.c | Applies an injected SCP send callback to the server context for tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
375
to
+389
| /* file buffer */ | ||
| ssh->scpFileBuffer = (byte*)WMALLOC(DEFAULT_SCP_BUFFER_SZ, ssh->ctx->heap, | ||
| DYNTYPE_BUFFER); | ||
| if (ssh->scpFileBuffer == NULL) { | ||
| WFREE(ssh->scpFileName, ssh->ctx->heap, DYNTYPE_STRING); | ||
| ssh->scpFileName = NULL; | ||
| return WS_MEMORY_E; | ||
| } | ||
| ssh->scpFileBufferSz = DEFAULT_SCP_BUFFER_SZ; | ||
| WMEMSET(ssh->scpFileBuffer, 0, DEFAULT_SCP_BUFFER_SZ); | ||
|
|
||
| /* reset per-file state so a reused connection starts a fresh transfer */ | ||
| ssh->scpFileOffset = 0; | ||
| ssh->scpBufferedSz = 0; | ||
| ssh->scpFileHeaderSent = 0; |
- Gate header on new scpFileHeaderSent flag, not scpFileOffset==0 - A send callback returning 0 bytes first no longer re-sends header - Skip zero-length SCP_SEND_FILE send to avoid empty CHANNEL_DATA - Reset offset/bufferedSz/flag in ScpSourceInit for connection reuse - Add test_wolfSSH_SCP_SendZeroFirst regression (func_args scp_send hook) - Zero func_args in kex.c/testsuite.c so the new scp_send field is not read uninitialized Issue: ZD-22176
ejohnstown
force-pushed
the
fix-scp-dupe-header
branch
from
July 23, 2026 22:54
e0d32bb to
ec84812
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.
Issue: ZD-22176