Commit Graph

6728 Commits

Author SHA1 Message Date
Jakub Jelen
49ad84283e packet: Avoid hidden integer underflow
Originally reported by Brian Carpenter b@deepforkcyber.com

Based on the never complted MR !724

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Pavol Žáčik <pzacik@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/819>
2026-04-24 11:12:59 +02:00
YubarajDas
b2065f71c9 fix: replace str(n)(cat|cpy) with strl(cat|cpy)
Signed-off-by: YubarajDas <dasyubaraj2020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/796>
2026-04-24 11:11:24 +02:00
Nuhiat-Arefin
8b2809ae13 config_parser: cast isblank() arguments to unsigned char
isblank() is only defined for unsigned char values (or EOF). Passing a plain char can be undefined behaviour on platforms where char is signed and the input contains bytes with the high bit set. Cast the tokenizer inputs to unsigned char before calling isblank() so these ctype calls stay within their defined domain.

Signed-off-by: Nuhiat-Arefin <nuhiatarefin@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/806>
2026-04-23 13:36:15 +02:00
Nuhiat-Arefin
1e4ee79ad3 tests: cover Tag and Match tagged parsing
Signed-off-by: Nuhiat-Arefin <nuhiatarefin@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/806>
2026-04-23 13:36:14 +02:00
Nuhiat-Arefin
ce630497e8 config: implement Tag keyword and Match tagged predicate
Signed-off-by: Nuhiat-Arefin <nuhiatarefin@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/806>
2026-04-23 13:36:13 +02:00
Jakub Jelen
dce230e49d sftpserver: Avoid NULL pointer dereference on wrong initialization
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Pavol Žáčik <pzacik@redhat.com>
2026-04-21 21:08:52 +02:00
Jakub Jelen
f992fd627f sftpserver: Initialize pointer
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Pavol Žáčik <pzacik@redhat.com>
2026-04-21 21:08:52 +02:00
Shashank
effc68f71b examples: Add missing errno headers to fix macOS build
Added implicitly includes for <errno.h> or <ctype.h> to ssh_server.c
and sshd_direct-tcpip.c to fix build failures on macOS.

Signed-off-by: Shashank <shashank.442k@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/813>
2026-04-20 21:25:49 +02:00
Himaneesh Mishra
c853d86bb5 ci: add standalone header compilation check
Add a CI job that compiles headers under include/libssh in isolation to catch include-order dependencies.

The job uses an allowlist for existing standalone-compilation failures, reports regressions separately, and structures the log for easier review in GitLab.

Keep the check scoped to public headers, make the build directory configurable, and keep allowlist cleanup visible without failing the job just because the list can be reduced.

Signed-off-by: Himaneesh Mishra <himaneeshmishra@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/751>
2026-04-09 15:56:07 +02:00
Nikhil V
c099892257 ci: Integrate ClusterFuzzLite to run fuzzing in CI
Signed-off-by: Nikhil V <nikhilgreyshines@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/702>
2026-04-09 15:55:23 +02:00
Haythem666
dec1c8d8d8 tests: add unit tests for ssh_set_counters()
Signed-off-by: Haythem666 <haythem.farhat@epfl.ch>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/808>
2026-04-09 15:43:08 +02:00
Rui Li
89f6055ec6 tests: add auth flag gate, null session, and options coverage
Signed-off-by: Rui Li <ruili3422@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/792>
2026-04-09 14:40:57 +02:00
Rui Li
36116b814e auth: add option flag checks to public auth functions
Signed-off-by: Rui Li <ruili3422@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/792>
2026-04-09 14:40:56 +02:00
Manas Trivedi
08c7d67fac examples: replace atoi() with strtol() for safe number parsing
Replace all usages on atoi() in examples with strtol() and add validation
for the same.

Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:16:30 +02:00
ShreyasMahajann
51d715ec91 tests: extend ssh_options_getopt coverage for -q
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:15:27 +02:00
ShreyasMahajann
152fc6633e options: add -q quiet flag to CLI getopt
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:15:27 +02:00
ShreyasMahajann
b371214209 options: split out getopt cleanup
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-04-01 22:15:26 +02:00
Jakub Jelen
e9c523e317 Use SSH_LOG_STRERROR where applicable
There were few leftovers of strerror() after the introduction of
ssh_strerror() some years back so this replaces the outstanding
cases with the portable and thread safe variant.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-04-01 14:40:47 +02:00
Jakub Jelen
13112fbdaa priv: Introduce SSH_LOG_STRERROR to avoid repetitive code
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-04-01 14:40:46 +02:00
Jakub Jelen
bacdcff7a0 sftpserver: Rename ssh_str_error to avoid confusion with ssh_strerror
Use the new name sftp_strerror() to better describe the reality.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-04-01 14:40:45 +02:00
Jakub Jelen
527d3b22a1 tests: Add missing newline at the end of file
This is breaking MacOS and FreeBSD builds.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-03-30 10:42:48 +02:00
Nuhiat-Arefin
93108dd026 config: add Match version support
Signed-off-by: Nuhiat-Arefin <nuhiatarefin@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-28 19:51:32 +01:00
Manas Trivedi
8dc59ae8ac sftp: set missing error codes in sftp_init failure paths
Ensure ssh and sftp error codes are consistently set across all
failure paths in sftp_init(). One branch previously returned
-1 leading to ambiguous error reporting.

Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-28 19:50:50 +01:00
Jakub Jelen
a00fbfb800 gcrypt: Remove unused bignum_free()
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2026-03-27 15:11:00 +01:00
Jakub Jelen
3360e6e1a3 dh-gex: Remove unused bignum context
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2026-03-27 15:10:58 +01:00
Jakub Jelen
d8ccda1d6f dh: Validate peer public key
The RFC 4253, Section 8 says that the

   Values of 'e' or 'f' that are not in the range [1, p-1] MUST NOT be
   sent or accepted by either side.  If this condition is violated, the
   key exchange fails.

Originally reported by Oren Yomtov

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2026-03-27 15:10:55 +01:00
Pavol Žáčik
44b186fa17 channels: Fail when receiving max packet size 0
Do this both for SSH2_MSG_CHANNEL_OPEN and for
SSH2_MSG_CHANNEL_OPEN_CONFIRMATION. Using the
max packet size 0 would lead to an infinite loop
in channel_write_common.

Originally reported by Rinku Das on on 23th February.
Independently reported by Yi Lin on 26th February and
Haruto Kimura on 22nd March.

We do not consider this as a security issue as connecting
to untrusted servers on the internet brings much worse
security consequences than hanging your clinet.

Signed-off-by: Pavol Žáčik <pzacik@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-27 09:26:17 +01:00
Robert Pana
66285b3ce4 [examples/ssh_client.c] Implemented -E log_file flag to redirect logs
Signed-off-by: Robert Pana <robertpana2015@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-25 11:26:44 +01:00
Robert Pana
c81c6d897f [examples/ssh_client.c] Reformatted ssh_client.c to match coding style
Signed-off-by: Robert Pana <robertpana2015@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-25 11:26:44 +01:00
Haythem666
28947fb58b doc: add missing doxygen documentation for SFTP handles
Add @brief documentation for:
- sftp_handle struct and sftp_handle_remove function

Contributes to #342

Signed-off-by: Haythem666 <haythem.farhat@epfl.ch>
2026-03-25 11:19:31 +01:00
Mingyuan Li
6fc95e8d43 examples: Enable libssh_scp and scp_download on Windows
Both examples only depend on getopt, which is now provided by the
bundled fallback. Include the getopt wrapper header and move them
out of the UNIX-only build guard.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
715d79647d tests: Add dedicated unit tests for getopt abstraction
Add torture_getopt.c with 11 test cases covering basic option parsing,
arguments, optional arguments, unknown options, missing arguments,
BADARG colon behavior, double-dash termination, combined options,
optind advancement, reset behavior, and no-options edge case.
Registered in the unit test CMakeLists.txt.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
90169c598e tests: Enable getopt tests on all platforms
Remove _MSC_VER guards from torture_options_getopt and
torture_options_getopt_o_option so they run unconditionally,
now that a bundled getopt fallback is available.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
950f796aca options: Enable ssh_options_getopt on all platforms
Include the new platform-independent getopt wrapper header and remove
the #ifdef _MSC_VER guard that disabled ssh_options_getopt() on MSVC.
The function is now compiled unconditionally on all platforms.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
31a882016e options: Add platform-independent getopt wrapper header
Add include/libssh/getopt.h that transparently includes the system
<getopt.h> when available, or declares the bundled fallback interface
otherwise.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
d2f7994140 options: Add bundled getopt implementation from FreeBSD
Add a portable getopt() fallback for platforms that lack it (e.g. MSVC).
Based on FreeBSD lib/libc/stdlib/getopt.c (BSD-3-Clause), adapted by
replacing FreeBSD internal headers and _getprogname() with standard C
equivalents. Only compiled when HAVE_GETOPT is not defined.

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Mingyuan Li
9a2f23ee30 cmake: Add detection for getopt and getopt.h
Add CMake checks for the getopt function and getopt.h header to
prepare for a bundled getopt fallback on platforms that lack it
(e.g. MSVC).

Signed-off-by: Mingyuan Li <2560359315@qq.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 15:11:55 +01:00
Jakub Jelen
729a44e121 ci: Skip macos jobs on forks
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-03-24 10:58:22 +01:00
Jakub Jelen
051ac812db examples: Add warning about example code
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-03-24 10:58:11 +01:00
Haythem666
01772c4f79 pki: add ssh_key_type_and_hash_from_signature_name()
Merge ssh_key_type_from_signature_name() and ssh_key_hash_from_name()
into a single function ssh_key_type_and_hash_from_signature_name() to:

- Avoid double string comparisons on the same algorithm name
- Return SSH_ERROR on unknown/NULL input instead of silently returning SSH_DIGEST_AUTO
- Use strlen() before strcmp() to short-circuit string comparisons.

Handle GSSAPI "null" hostkey case in wrapper.c.
Add unit tests for the new function.

Fixes: https://gitlab.com/libssh/libssh-mirror/-/issues/355
Signed-off-by: Haythem666 <haythem.farhat@epfl.ch>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 10:50:39 +01:00
Manas Trivedi
9f7c596ca5 tests: add coverage for NULL session in ssh_channel_is_open
Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 10:15:06 +01:00
Manas Trivedi
34bbb48561 channels: add NULL session check in ssh_channel_is_open
Prevent potential NULL pointer dereference when accessing
channel->session->alive.

Signed-off-by: Manas Trivedi <manas.trivedi.020@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-24 10:15:05 +01:00
Jakub Jelen
f060583d6f tests: Generate coverage for fuzzing tests
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-19 22:16:17 +01:00
Bulitha Kawushika De Zoysa
a05b2b76be tests: initialize sftp test pointers to NULL
Signed-off-by: Bulitha Kawushika De Zoysa <bulithakaushika99@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-19 17:06:05 +01:00
Bulitha Kawushika De Zoysa
c9f34ac55f sftp: Add support for the users-groups-by-id@openssh.com OpenSSH extension on the server side.
Signed-off-by: Bulitha Kawushika De Zoysa <bulithakaushika99@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-19 17:06:04 +01:00
Ahmed hossam
bc24bba176 docs: Add documentation for test_server functions
Signed-off-by: Ahmed hossam <ahmed.hossambahig@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-19 17:03:42 +01:00
Colin Baumgarten
3154a4ab8d sftpserver: Fix client messages being ignored if sent at a high rate
When using OpenSSH scp to read files larger than a few hundred
kilobytes, downloads stall and never finish. A workaround is to
pass -Xnrequests=1 to scp, which will cause scp to only do a
single concurrent SFTP read request at a time.

The cause for the problem is that if SFTP client messages are
received at a high rate, sftp_channel_default_data_callback() will
potentially be called with multiple messages in the incoming data
buffer, but only the first message will be extracted and handled.

So add a loop to extract as many SFTP client messages as available
from the incoming data buffer.

Signed-off-by: Colin Baumgarten <colin.baumgarten@hubersuhner.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-17 12:01:15 +01:00
Sudharshan Hegde
9478de8082 doc: add missing Doxygen comments and fix documentation style
- Add missing @brief, @param, and @return docs across src/ and include/
- Fix blank lines between doc comments and function definitions
- Move function docs from headers to corresponding .c files
- Use named constants (SSH_OK, SSH_ERROR, SSH_TIMEOUT_INFINITE) in docs
- Fix parameter ordering in error.c, buffer.c, log.c docs
- Place #ifdef-guarded docs inside their respective #ifdef blocks

Signed-off-by: Sudharshan Hegde <sudharshanhegde68@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2026-03-17 11:46:11 +01:00
Shreyas Mahajan
e927820082 Make headers self-contained and include-order independent
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:07:16 +01:00
ShreyasMahajann
67950c620d misc: Reformat struct ssh_list members to use 4-space indentation
Signed-off-by: Shreyas Mahajan <shreyasmahajan05@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2026-03-16 19:07:16 +01:00