Repository navigation
Conversation
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
tests/test_simple.c:154
- These test failure messages print libssh2_int64_t using %lld, which is not portable on older MSVC. Use SSH2_INT64_T_FORMAT (defined in libssh2_priv.h) to format libssh2_int64_t consistently.
fprintf(stderr, "scp_parse partial-name: prc=%d mode=%ld size=%lld\n",
prc, mode, (long long)size);
tests/test_simple.c:184
- This test failure message prints libssh2_int64_t using %lld. Use SSH2_INT64_T_FORMAT so the test program builds on older MSVC/Windows toolchains.
}
/* Malformed: bad mode */
src/scp.c:809
- This trace log prints scpRecv_size (libssh2_int64_t) via a cast to long and %ld, which can truncate large file sizes and is inconsistent with other SCP logging/formatting in this file. Use SSH2_INT64_T_FORMAT and pass scpRecv_size directly.
sb->st_mtime = session->scpRecv_mtime;
sb->st_atime = session->scpRecv_atime;
sb->st_size = (libssh2_struct_stat_size)session->scpRecv_size;
Contributor
Author
|
Addressed review notes:
Latest tip: |
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
tests/test_simple.c:176
prefix_lenis derived fromsnprintf()without checking for a negative return or truncation. Ifsnprintf()ever fails (negative) or returns a value >=sizeof(long_line), the cast tosize_tcan makememset(long_line + prefix_len, ...)underflow/overflow and write out of bounds. Since the prefix is a constant string, it’s safer to avoidsnprintf()entirely and copy the literal with a known length.
prefix_len = (size_t)snprintf((char *)long_line, sizeof(long_line),
"C0644 99 ");
memset(long_line + prefix_len, 'a',
sizeof(long_line) - prefix_len);
vszakats
added a commit
that referenced
this pull request
Jul 23, 2026
To apply to all test apps. Prior to this patch it was set for fixtures only. Ref: #2408 (comment) Closes #2417
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
vszakats
reviewed
Jul 23, 2026
libssh2_scp_recv2 stored the server "Cmode size name\n" line in a fixed
256-byte session buffer. Mode and size always fit early, but a long
basename made the line exceed the buffer and fail with
LIBSSH2_ERROR_SCP_PROTOCOL ("Unterminated response from SCP server").
Parse mode and size as soon as those fields are complete. If the buffer
fills before the trailing newline, drain the unused basename until '\n'
and continue with the SCP ACK. Basename is not used by libssh2.
Add unit coverage in test_simple for the parser, including a full
SSH2_SCP_RESPONSE_BUFLEN buffer shaped like issue libssh2#1738.
Fixes libssh2#1738
Signed-off-by: Sebastien Tardif <[email protected]>
Signed-off-by: Sebastien Tardif <[email protected]>
- Drop braces around single-statement if/while in ssh2_scp_parse_c_fields - Remove GitHub issue numbers from comments - Use ssh2_snprintf in the long-name unit test (MSVC-compatible) Signed-off-by: Sebastien Tardif <[email protected]>
Avoid hard-coded %lld for libssh2_int64_t so older MSVC toolchains print sizes correctly (matches scp.c and SSH2_INT64_T_FORMAT). Signed-off-by: Sebastien Tardif <[email protected]>
Maintainer note: ssh2_snprintf is not available to tests without a build overhaul. Build the long-name fixture with memcpy, and print sizes with %lu + unsigned long cast for portable test fprintf. Also report "Invalid response" when a full buffer parses as malformed rather than always "Unterminated". Signed-off-by: Sebastien Tardif <[email protected]>
Signed-off-by: Sebastien Tardif <[email protected]>
Standard snprintf is available in tests (maps to _snprintf on old MSVC). Fill the remaining basename bytes with memset. Signed-off-by: Sebastien Tardif <[email protected]>
Signed-off-by: Sebastien Tardif <[email protected]>
libssh2_setup.h only maps snprintf to _snprintf when LIBSSH2_TESTS is set (or when not building the library). test_simple includes libssh2_priv.h directly without that define, so VS2010 treated snprintf as undefined under /WX. Match session_fixture.h: define LIBSSH2_TESTS before the priv header. Signed-off-by: Sebastien Tardif <[email protected]>
- Parse buffer as const char * (fewer casts at call sites / tests) - Check snprintf return before filling the long-name fixture - Single-line memset for the basename fill - Drop local LIBSSH2_TESTS define (build sets it for all tests after libssh2#2417) Signed-off-by: Sebastien Tardif <[email protected]>
SebTardif
force-pushed
the
fix/scp-recv-long-name
branch
from
July 23, 2026 22:01
9ec3260 to
7d75c1f
Compare
Contributor
Author
Signed-off-by: Sebastien Tardif <[email protected]>
Member
|
Thank you, merged now! |
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.
Summary
libssh2_scp_recv2fails withLIBSSH2_ERROR_SCP_PROTOCOL("Unterminated response from SCP server") when the server SCP
Clineexceeds the fixed 256-byte response buffer. Mode and size always fit early;
long basenames overflow the buffer.
Parse mode and size as soon as those fields are complete. If the buffer
fills before the trailing newline, drain the unused basename until
\nand continue with the SCP ACK. libssh2 does not use the basename.
Evidence
tests/test_simplecovers short lines, partial name, incompletesize, full 256-byte long-name buffer, and malformed mode
Fixes #1738