Also:
- openssl: drop redundant local variable in non-OpenSSL3 branch.
- x11: drop redundant cast.
- silence false positives.
Follow-up to 0b915eab67#2586Closes#2588
Replace `HAVE_GETTIMEOFDAY` with `_MSC_VER`. Assuming it everywhere
except on MSVC. On MSVC, fill in the missing function with a local
implementation copied from `src/misc.c`.
To improve building standalone by reducing the reliance on autotools,
cmake configure. Also to bring MSVC builds to the same functionality as
other platforms.
Cherry-picked from #2485Closes#2491
Drop feature detection for it at configure time.
To simplify, improve configure performance, make examples build better
standalone, and sync with curl.
Closes#2467
Drop feature detection for it at configure time.
To simplify, improve configure performance, make examples build better
standalone, and sync with curl.
Closes#2466
- knownhost: add link to file format.
- drop redundant parentheses.
- move literals to right-hand side of comparisons.
- unfold lines, drop empty lines.
Closes#2463
By bumping internal mtime/atime from `long` to `time_t`, and adjusting
internals to read and log these as 64-bit values.
Before this patch, these internal variables used `long`.
Also: show fileinfo in scp read examples.
Closes#2460
- drop redundant `== -1` to match rest of code.
- sync outlier pattern to init `struct string_buf` `dataptr`, to drop
repeat code and casts.
- drop redundant parentheses.
- add const to casts where missing.
Closes#2437
It wasn't needed anymore for `write()` in contratry to the comment,
because mapping it earlier to `_write()` in examples. But, it was needed
again for `strdup()` due to a regression. Fix it by mapping it again to
`_strdup()` in examples.
Also: document `vsnprintf()` used in tests.
Follow-up to ca43b304cf#2042
Follow-up to e8e6bc2c50#1688Closes#2332
Low-level logic copied from curl, and adapted to libssh2.
Also: use secure fopen CRT functions.
Credits-to: Jay Satiro
Credits-to: Viktor Szakats
Closes#2318
- cmake: do not build examples automatically. This makes the
`BUILD_EXAMPLES=OFF` option redundant.
- cmake: build all examples with target `libssh2-examples`.
- cmake: build-test all examples with target `libssh2-examples-build`.
To save linking them 23 times in CI.
- autotools: add root `examples` build target to build examples.
- CI: build examples in a separate step.
(for autotools, make them not build in the main build step by
configuring with `--disable-examples-build`)
To make the build more transparent, scale better, be faster in CI, also
syncing with curl.
Slight downsides after this patch:
- cmake and autotools have different default behavior for building
examples.
- cmake needs an extra step to build examples. (an explicit option is
planned to restore the old behavior.)
Also:
- sync BSD matrix build-tool naming with rest of jobs.
Closes#2276
Also:
- sync with canonical `BSD-3-Clause.txt`:
- number the clauses.
- wording in the 3rd clause.
- add 'All rights reserved.' where missing.
- agent: sync with rest of files.
- agent: merge two, identical, embedded headers.
- fix comments nits found nearby.
Closes#2247
Also bail out right away to avoid other issues down the line.
Seen in CI when Libgcrypt could not negotiate keys with modern sshd
server on Ubuntu 26.04:
```
26: 1..2
26: Failure establishing SSH session: -5
26: Fingerprint: /home/runner/tests/test_sshd.test: line 151: 8233 Segmentation fault
(core dumped) ${LIBSSH2_TEST_EXE_RUNNER:-} "${test}"
26: not ok 1 - sshd-test_ssh2
26: libssh2_session_handshake failed (-5): Unable to exchange encryption keys
```
Ref: https://github.com/libssh2/libssh2/actions/runs/28582866680/job/84747161004?pr=2174
Ref: #2174Closes#2179
Seen when building in cmake Release config on Linux:
```
example/scp_nonblock.c:254:17: error: ignoring return value
of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
254 | write(1, mem, (size_t)nread);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/28063084190/job/83084069984
```
example/sftp.c:73:9: error: ignoring return value of ‘fgets’ declared
with attribute ‘warn_unused_result’ [-Wunused-result]
73 | fgets(buf, sizeof(buf), stdin);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/28064008314/job/83084278796Closes#2122
Introduce and use the local name `ssh2_snprintf()` instead, and map it
to system `snprintf()` when safe, otherwise directly call the local
implementation already using this name.
Also: adjust checksrc rules.
Closes#2103
This feature has been permanently enabled since the initial commit
adding CMake builds to libssh2. Limited to libssh2's own DLL (if built
that way), and OpenSSL's crypto DLL. While limited to these two DLLs
(and not supporting other dependencies), history shows this feature was
prone to break, and recently started breaking parallel builds, due to
MSBuild failing while copying the DLLs to the same location in
concurrent threads. This recently made MSVC GHA jobs flaky.
It's also a potential performance and disk trashing issue when copying
large DLLs (OpenSSL `libcrypto-*.dll`) on each build, for each of the 52
(at the time of this commit) targets. That's potentially 104 copy
operations. Perhaps this could be limited to once per each target
directory, but that's adding even more complexity and development time.
There is also no generalized/trivial way to pick up the complete set of
DLL dependencies; e.g. libcrypto.dll may need other DLLs. Another
disadvantage is copying around DLLs eventually ends up contributing to
DLL-hell, copies may go stale, picked up when undesired, or due the
heuristic detection, they may not match the dependency version/instance
actually linked. The copying was done on all platforms, while typically
the issue is exclusive to Windows MSVC (and it's also where it breaks.)
As a replacement, I propose to add any necessary DLL location to `PATH`
before running examples or tests. It works well in CI. Also in curl.
Fixing:
```
Version: 20260616.203.1
[...]
MSBuild version 17.14.40+3e7442088 for .NET Framework
[...]
D:/a/libssh2/libssh2/bld/tests/Release\libssh2.dll: message: deploying dependencies
D:/a/libssh2/libssh2/bld/tests/Release\libcrypto-3-x64.dll: message: deploying dependencies
The process cannot access the file because it is being used by another process.
[...]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmDone [D:\a\libssh2\libssh2\bld\tests\test_auth_pubkey_ok_rsa_sha2_256_signed.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd [D:\a\libssh2\libssh2\bld\tests\test_auth_pubkey_ok_rsa_sha2_256_signed.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :VCEnd" exited with code 32. [D:\a\libssh2\libssh2\bld\tests\test_auth_pubkey_ok_rsa_sha2_256_signed.vcxproj]
D:/a/libssh2/libssh2/bld/tests/Release/test_auth_keyboard_info_request.exe: message: deploying dependencies
D:/a/libssh2/libssh2/bld/tests/Release\libcrypto-3-x64.dll: message: deploying dependencies
test_auth_pubkey_ok_rsa_openssh.vcxproj -> D:\a\libssh2\libssh2\bld\tests\Release\test_auth_pubkey_ok_rsa_openssh.exe
```
Refs (MSVC):
https://github.com/libssh2/libssh2/actions/runs/27838566519/job/82392203784 OpenSSL
https://github.com/libssh2/libssh2/actions/runs/27838566519/job/82392203753 WinCNG
https://github.com/libssh2/libssh2/actions/runs/27823077802/job/82340632890 WinCNG UWP
Examples, with shared libssh2:
combined with WINCNG:
Before: https://github.com/libssh2/libssh2/actions/runs/27891639324/job/82535960547 (277 steps)
After: https://github.com/libssh2/libssh2/actions/runs/27901568257/job/82562736781 (229 steps)
combined with OpenSSL:
Before: https://github.com/libssh2/libssh2/actions/runs/27902131772/job/82564199274 (326 steps)
After: https://github.com/libssh2/libssh2/actions/runs/27902733625/job/82565870012 (229 steps)
Observe these steps no longer performed:
```
D:/a/libssh2/libssh2/bld/example/Release\libcrypto-3-x64.dll: message: deploying dependencies
D:/a/libssh2/libssh2/bld/example/Release\libssh2.dll: message: deploying dependencies
```
Ref: #2078
Ref: 1e5e2923f7
Follow-up to a95a02c8fb#2093
Follow-up to 97d8e8d49a#2091
Follow-up to d652ba0205#2090
Follow-up to dd50a41152#1638
Follow-up to 694b9d964b#1610
Follow-up to 97417ad37f#899
Follow-up to 19884e5055#818
Follow-up to 6bf8983368Closes#2101
As of gcc-16, this still causes a false positive:
```
example/ssh2.c: In function 'main':
example/ssh2.c:215:34: error: '__builtin_snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
215 | snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
| ^~~~~~~
example/ssh2.c:215:40: note: format string is defined here
215 | snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
| ^
example/ssh2.c:215:13: note: '__builtin_snprintf' output 17 or more bytes (assuming 18) into a destination of size 17
215 | snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
| ^~~~~~~~
example/ssh2.c:216:34: error: '__builtin_snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
216 | snprintf(fn2, fn2sz, "%s/%s", h, privkey);
| ^~~~~~~
example/ssh2.c:216:40: note: format string is defined here
216 | snprintf(fn2, fn2sz, "%s/%s", h, privkey);
| ^
example/ssh2.c:216:13: note: '__builtin_snprintf' output 13 or more bytes (assuming 14) into a destination of size 13
216 | snprintf(fn2, fn2sz, "%s/%s", h, privkey);
| ^~~~~~~~
```
By bumping the allocated buffers by one byte, the above disappears, but
remains in gcc-13. Fix by bumping buffer by one more byte.
```
example/ssh2.c: In function ‘main’:
example/ssh2.c:228:40: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
228 | snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
| ^
example/ssh2.c:228:13: note: ‘snprintf’ output 3 or more bytes (assuming 4) into a destination of size 3
228 | snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example/ssh2.c:229:40: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
229 | snprintf(fn2, fn2sz, "%s/%s", h, privkey);
| ^
example/ssh2.c:229:13: note: ‘snprintf’ output 3 or more bytes (assuming 4) into a destination of size 3
229 | snprintf(fn2, fn2sz, "%s/%s", h, privkey);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/27890978881/job/82534253967#step:24:67Closes#2100
- factor out the single-underscored name.
- rename double-underscored name into the `LIBSSH2_` namespace.
Spotted by GitHub Code Quality
Follow-up to 694b9d964b#1610
Follow-up to 6bf8983368Closes#2090
- man pages: grammar
- examples: add missing parentheses to macro values
- examples: replace `write()` with `_write()` on Windows.
(to avoid warnings.)
- examples, tests: drop redundant NULL assigments.
- examples: fix to cleanup on error in ssh2_echo, ssh2_exec.
- libssh2.rpgle.in: make hex notation consistent in comment.
- chacha, session.h: avoid comparison with literal NULL.
- prefer 'unrecognized' vs 'unknown' in error messages.
- mbedtls: sync a code pattern with others in the code in
`ssh2_rsa_new()`.
- openssl: declutter and update comment for wolfSSL `HMAC_Update()`
exception. Also drop FIXME as the upstream incompatibility seems
intentional.
- pem, userauth, wincng: fix, clarify error messages.
- wincng: add explanation for `NOLINT` exception, reword another
comment.
(suggested by Copilot)
- misc: drop redundant parentheses.
- test_read: fix a type mismatch.
- openssl: use indexed syntax for readability.
- vms/man2help: fix tool name is help text.
- formatting: reflow, newlines, spaces, comment typos.
Some of these reported by GitHub Code Quality / Copilot.
Closes#2042
Replace with `ssh2_deb()`.
Also:
- adjust checksrc options to verify.
- checksrc-all.pl: fix an issue preventing picking up `tests/.checksrc`.
Follow-up to c090b696c6#1556
Follow-up to af1e591eee#796Closes#1997
- sync picky compiler warning options with curl:
- update version mappings for latest Apple clang.
- replace `-pedantic` with `-Wpedantic` on newer toolchains.
- adjust warning cutoff versions.
- enable new picky warnings.
- unlock picky warnings for most recent MSVC.
- GHA: bump some MSVC jobs to to VS2026.
Fix fallouts:
- configure: replace `-I` with `-isystem` for dependency headers.
Notably it silences picky warnings otherwise found in 3rd-party
headers, e.g. `-Wreserved-identifier` in `gpg-error.h`,
`openssl/lhash.h`, `wolfssl/wolfcrypt/hmac.h`, or
`-Wcast-function-type-strict` in `openssl/rsa.h`.
It also aligns autotools builds with CMake (and curl builds).
Logic copied from curl.
- example/x11: fix to not use reserved symbols.
- include, src/libssh2_priv.h: silence `-Wreserved-identifier` locally.
May be fixed for real in a future patch.
- avoid using reserved C++ keyword `public`.
- openssl: silence `-Wcast-function-type-strict` locally for
non-OpenSSL3 builds.
- mbedtls, openssl: fix potentially uninitialized variable warnings.
(extend to all compilers from MSVC in openssl)
- fix `LIBSSH2_SOCKET_MASK` signedness on Windows.
- wincng: apply casts from `int` to `enum` to silence
`-Wimplicit-int-enum-cast`.
- configure: disable `-Wleading-whitespace=spaces` to due
incompatibility with `AC_FUNC_ALLOCA`.
- packet: fix to pass `int` as mask length.
- fix `-Wformat-signedness`.
- src/libssh2_priv.h: silence `-Wreserved-macro-identifier` locally for
mingw-w64 builds.
- GHA: add workaround for missing NSIS on windows-2025 runner images.
Closes#1972
Checker script and wordlist comes from curl.
Also:
- checksrc.pl: sync up with curl.
- unfold an IETF URL.
- update all IETF URLs where missing.
Closes#1959
- apply manually selected clang-format fixes.
- apply manual formatting fixes.
- move return type inline with the declaration.
(for private APIs)
- os400qc3: fix missed `_libssh2_dh_ctx` -> `libssh2_dh_ctx`.
Follow-up to 689b202320#1923
- os400qc3: drop redundant line-continuation backslashes.
- delete copy of function name from function top comments.
- move literal to right hand side in a couple of comparisons.
- drop redundant `extern` keywords.
Follow-up to 6ffb96321c#1935Closes#1936
- reflow a few lines.
- drop space between cast and value. To match majority of code.
- drop space between `*` and variable in declarations and argument
lists. To match majority of code.
Closes#1899
- fix wrong data length in `libssh2_channel_write()` call.
- fix wrong buffer size in `libssh2_channel_read()` call.
- check success of `libssh2_channel_read()` call, show error on failure.
- fix writing raw data to stdout.
- fix grammar in error messages.
Also in ssh2_agent_forwarding, ssh2_exec:
- use `else if` in two other examples.
- fix to not display `libssh2_channel_read()` when zero.
Pointed out by GitHub Code Quality
Follow-up to 32080def94Closes#1886