1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-09-17 00:22:05 +03:00

3083 Commits

Author SHA1 Message Date
Viktor Szakats
3389a125f3 ci/GHA: fixup comments after actions bump [ci skip] 2025-09-16 14:01:26 +02:00
Viktor Szakats
5bd1baed82 SECURITY.md: mention GitHub PVR as an option
libssh2 now accepts security reports via:
https://github.com/libssh2/libssh2/security

Closes #1664
2025-09-15 21:50:47 +02:00
dependabot[bot]
765c102f32 ci/GHA: bump actions/checkout from 4.2.2 to 5.0.0 (#1665) 2025-09-15 21:48:49 +02:00
Viktor Szakats
629904e4e4 ci/GHA: rename GHA CodeQL configuration
Follow-up to 1ec4e27f85 #1655
2025-09-15 15:16:47 +02:00
Viktor Szakats
51b35d1b7a fix two NULL checks
- userauth: fix NULL dereference when out-of-memory.
  Also fix indentation.
  Follow-up to 3a6ab70dcf #1314

- openssl: drop redundant NULL check and logic.
  Follow-up to ed439a29bb #698

Pointed out by CodeQL

Closes #1656
2025-09-15 01:16:36 +02:00
Viktor Szakats
199526f941 tidy-up: Makefile.am comments and copyright header
Closes #1662
2025-09-14 23:44:40 +02:00
Viktor Szakats
fdd6aa2cfa cmake: initialize __runtime_dependencies variable
To silence cmake `--warn-uninitialized` warning.

Follow-up to 694b9d964b #1610

Closes #1661
2025-09-14 23:37:53 +02:00
Viktor Szakats
746de2ad88 ci/GHA: test WinCNG with CodeQL
Closes #1659
2025-09-14 13:48:14 +02:00
Viktor Szakats
664d7654c5 build: fix/extend Apple clang and mainline llvm version translations
Ref: https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
Ref: https://github.com/curl/curl/pull/18477

Closes #1658
2025-09-14 12:43:29 +02:00
Viktor Szakats
63ae236f28 ci/GHA: extend CodeQL to libgcrypt, mbedTLS, wolfSSL, zlib builds
Closes #1657
2025-09-14 01:18:00 +02:00
Viktor Szakats
1ec4e27f85 ci/GHA: add CodeQL jobs for GHA and C
Closes #1655
2025-09-14 00:13:39 +02:00
Viktor Szakats
c3e6dbd469 tidy-up: fix typos found by typos-cli 1.36.2
Closes #1654
2025-09-13 22:58:06 +02:00
Viktor Szakats
4cb8398fa7 ci/GHA: document permissions as required by zizmor 1.13.0
Closes #1653
2025-09-13 18:01:12 +02:00
dependabot[bot]
a0dafb3197 ci/GHA: bump actions
actions/upload-artifact from 4.6.1 to 4.6.2
cygwin/cygwin-install-action from 5 to 6
msys2/setup-msys2 from 2.26.0 to 2.29.0

Closes #1649
Closes #1650
Closes #1651
2025-09-09 11:29:06 +02:00
Viktor Szakats
60c528be07 ci/GHA: enable Dependabot to bump GitHub Actions 2025-09-09 09:19:22 +02:00
Viktor Szakats
09eb59e3bb cmake: use C compiler version (not C++), fix a fallout
This version check may have never worked before this patch. Fixing it
uncovered another issue with assembling `gcov` compiler options. Fix
that issue too.

Follow-up to 09f0ffd9fb
Closes #1648
2025-09-03 17:25:32 +02:00
Viktor Szakats
25ed4d74de cmake: make clean-coverage target portable
By using cmake's built-in commands instead of expecting the shell
to support `rm -rf`.

Closes #1647
2025-09-03 13:40:38 +02:00
Viktor Szakats
2fcba30a7e GHA: stay on windows-2022 runners
windows-latest is soon to bump to window-2025. windows-2025 drops
the fast D: drive and becomes slower overall. Stay on 2022.

Closes #1645
2025-08-30 11:30:54 +02:00
Will Cosgrove
d1c0e14d2a Improve known_hosts parsing and harden _libssh2_base64_encode() (#1641)
Notes:
Added additional base64 decoding validation when parsing known_hosts and no longer assume what is going into _libssh2_base64_encode() is a null terminated C string, input now must have a length and buffer.

Reported by:
Dhiraj Mishra mishra.dhiraj95@gmail.com

Credit:
Will Cosgrove

Reviewed by:
Michael Buckley
2025-08-25 09:36:40 -07:00
trustytrojan
dd50a41152 cmake: add LIBSSH2_DISABLE_INSTALL option
To disable all installation targets.

Closes #1638
2025-08-24 18:15:10 +02:00
Viktor Szakats
0ec6b3e842 GHA: bumps, delete two jobs with fallouts
Bump GHA actions and locally built crypto libs to their latest versions.

Also delete:

- linux autotools libgcrypt i386 job that started failing
  around 2 weeks ago, unrelated to any recent libssh2 changes.
  Good: https://github.com/libssh2/libssh2/actions/runs/16805274874/job/47596007399
  Bad: https://github.com/libssh2/libssh2/actions/runs/16900307497/job/47877965823
  ```
  # TOTAL: 43
  # PASS:  8
  # SKIP:  0
  # XFAIL: 0
  # FAIL:  35

  FAIL: test_aa_warmup
  ====================
  [...]
  ```

- OmniOS job which started failing after bumping in this PR from
  vmactions/omnios-vm@16b5996777 # v1
  to
  vmactions/omnios-vm@c31844c7ab # v1
  ```
  1..2
  libssh2_userauth_list failed (0):
  ok 1 - sshd-test_ssh2
  PASS: test_sshd.test 1 - sshd-test_ssh2
  not ok 2 - sshd-test_auth_pubkey_ok_ed25519
  FAIL: test_sshd.test 2 - sshd-test_auth_pubkey_ok_ed25519
  ```

Closes #1642
2025-08-24 17:23:27 +02:00
Viktor Szakats
714fa876ee cmake: make the ExternalProject test work
By micromanaging the project dependency and its inclusion into the test
project. It feels like an awkward construct, but perhaps better than
nothing.

It's also fragile because it's a static build with no assistance from
the external project (curl in this case). Mitigated in test by disabling
all dependencies and some features.

Since there is no special core cmake logic to be tested here, in CI
the test is tested really. To keep CI jobs at minimum, only add 3 of
them, taking 26s in total. (All 6 would take 203s.)

Follow-up to 77df767784 #1589

Closes #1637
2025-08-07 10:38:18 +02:00
Kian Kasad
30203f167b docs: improve man page for libssh2_channel_request_auth_agent
Mention that the callback is needed for full functionality.

This is inspired/copied from the existing X11 man pages.

Closes #1503
2025-07-22 14:13:01 +02:00
Josh Brobst
30befffe04 kex: fix DH-GEX-sha256 bignum initialization
In `kex_method_diffie_hellman_group_exchange_sha256_key_exchange`,
`p` and `g` are later initialized with `_libssh2_bn_from_bin`, so they
should be initially created using `_libssh2_bn_init_from_bin` rather
than `_libssh2_bn_init`, as is done in
`kex_method_diffie_hellman_group_exchange_sha1_key_exchange`.

Fixing memory leaks when using the libgcrypt backend.

Follow-up to 09c5e59933
Ref: https://web.archive.org/web/trac.libssh2.org/ticket/168

Closes #1599
2025-07-21 21:26:32 +02:00
Will Cosgrove
cea8783ed8 Fix small leak in base64_encode() with empty data #1627 (#1630)
Fix small memory leak when trying to encode base64 data with no data.

Credit:
Liu Xing Yu
2025-07-21 11:48:25 -07:00
Will Cosgrove
aa4c7b5b96 Handle malformed comments in known_hosts parsing #1628 (#1629)
Notes:
Handle malformed comment in known_hosts parsing to avoid buffer overflow.

Credit:
Liu Xing Yu
2025-07-21 11:46:58 -07:00
Ryan Kelley
992dafbc7f scp: fix NULL dereference in path arg of send/recv (#1625)
Notes:
* Error handling if path for scp is NULL

Reported-by:
Liu Xing Yu

Credit:
Ryan Kelley
2025-07-21 10:02:42 -07:00
Josh Brobst
f46422223f libgcrypt: add support for RSA SHA-256/SHA-512
Closes #1600
2025-07-21 02:01:02 +02:00
Viktor Szakats
ad8e924583 cmake: fixup Libs.private lib order
- Reworking the `Libs.private` collector logic for INTERFACE targets,
  broke the original lib order. Fix it by going back a single loop
  to retain order.
  Follow-up to df0563a857 #1535

- Implement the above with one change: move implicit CMake libs
  to the end of the list (was: the beginning).
  I expect these to be libs that any custom libs may depend on,
  like system libs, C runtime, compiler runtime lib.
  Follow-up to c87f129630 #1466

Closes #1623
2025-07-14 01:34:40 +02:00
Viktor Szakats
e1da7b2cb8 cmake: de-duplicate LIBSSH2_PC_LIBS_PRIVATE more carefully
`LIBSSH2_PC_LIBS_PRIVATE` ends up in `Libs.private` in `libssh2.pc`.

The order and duplication may be significant for linkers that rely on
strict lib order and unable to resolve symbols without it. Such linker
is binutils `ld`. De-duplication can break it.

As of now there is no purposeful duplication in libs in libssh2, thus
the de-duplication most likely did not affect actual builds.

It was originally introduced to avoid a repeat `-lz` (with
a zlib-enabled OpenSSL or wolfSSL build.) To keep this feature, this
patch makes sure to only delete duplicates that are next to each other.

Follow-up to 6464301820 #1131

Closes #1621
2025-07-14 01:34:40 +02:00
Viktor Szakats
4e08dac73d cmake: tidy up add_feature_info() formatting
Closes #1622
2025-07-13 21:24:10 +02:00
Viktor Szakats
dfe7aca9b0 ci/GHA: allow more time for 'CM integration' job
Sometime 5 minutes wasn't enough for the Windows platform.

Ref: https://github.com/libssh2/libssh2/actions/runs/16251541971/job/45881908411?pr=1622
Ref: https://github.com/libssh2/libssh2/actions/runs/15478243283/job/43578759660?pr=1600
2025-07-13 19:25:17 +02:00
Viktor Szakats
300da4e2ff cmake: pre-fill more, simplify control flow
Closes #1620
2025-07-13 14:34:17 +02:00
Viktor Szakats
22784a56e2 cmake: drop redundant -lws2_32 meant for libssh2.pc
The `libssh2.pc` generator logic automatically adds `-lws2_32` while
parsing `LIBSSH2_LIBS`, which contains this lib already. Then discard
the duplicate.

This patch introduces a change in the position of `ws2_32` within
the lib list advertised via `libssh2.pc` for static builds.

This order might in cases by significant, but:

- libssh2 no longer links against `libssl`, which was the library
  also referencing `ws2_32` and breaking picky binutils `ld` linker
  when not passed in strict dependency order.
  Ref: c84745e34e #1128

- since switching to INTERFACE targets, cmake messes up the lib order
  anyway, adding `OpenSSL:Crypto` last, instead of `ws2_32`. This did
  not seem to cause an issue so far.
  Ref: df0563a857 #1535

For these reasons it seems unlikely this position change could break
Windows OpenSSL static gcc/ld builds relying on `libssh2.pc` for their
lib list. It least no more than it was before this patch.

Turns out these theories don't stand in practice and the order is broken
possibly by introducing INTERFACE targets, with or without this patch.
`libcrypto` (tested with LibreSSL) is in fact depending on `ws2_32`, and
the `bcrypt` dependency is also causing breakage with picky binutils ld.
I may try addressing it in a separate PR.

Ref: 33b6d5f89d #827
Ref: 31fb8860db #811

Closes #1619
2025-07-13 14:34:17 +02:00
Viktor Szakats
e62a72b22f ci/GHA: move CI checks to Linux, other CI tweaks
Also:
- merge CI check and shellcheck jobs into a single one.
  To share the same shellcheck version and less overhead.
- use `set -eu` in more scripts.
- make sure CI scripts run from any cwd.
  To make it easy to run them on local machine.
- minor tidy-ups.

Closes #1618
2025-07-13 11:21:39 +02:00
Lucas Queiroz
98cd10d1c1 INSTALL_CMAKE: fixes build result directories
In the CMake installation instructions, the resulting static library,
examples and tests are actually found in `bld`, not in `bin`.

Closes #1617
2025-07-13 11:21:39 +02:00
Viktor Szakats
723b701715 build: tidy up comments on Makefile.inc variables
Closes #1615
2025-07-02 12:02:09 +02:00
Viktor Szakats
339ea0f61f GHA: fix new zizmor warnings
Also:
- fix old yamllint warnings.
- make quoting more consistent.
- drop stray step name: "checkout".
- merge REUSE workflow into main CI one.

Closes #1614
2025-07-02 11:03:41 +02:00
Viktor Szakats
694b9d964b cmake: add linter, fix issues
Ref: https://cmake-format.readthedocs.io/en/latest/cmake-lint.html
Ref: https://github.com/cheshirekow/cmake_format

Closes #1610
2025-06-11 07:09:10 +02:00
Viktor Szakats
d7cf63bb05 GHA: fix zizmor and shellcheck warnings, verify in CI
Closes #1609
2025-06-09 16:40:26 +02:00
chrisgch
d8ae40bad0 Fixes when server/client uses encryption method with integrated MAC and the other doesn't (#1582)
Notes:
Connection fails when server/client uses one encryption method with integrated MAC and one without.

Credit:
Christian Ghisler
2025-05-21 13:38:11 -07:00
Anders Borum
9136cc763b agent: fix byte amount copied for method in libssh2_agent_sign
It looks like the incorrect length is used to copy the public key method
into the session in `libssh2_agent_sign()` and while the public key type
at the start of a identity blob is often identical to the public key
method it might not always be such as when method is `rsa-sha2-256` for
`ssh-rsa` keys.

Closes #1603
2025-05-17 23:46:45 +02:00
Viktor Szakats
201c368aa1 ci/GHA: avoid touching GITHUB_ENV
To make configuration simpler, easier to understand and possibly more
secure.

Closes #1598
2025-05-08 23:50:28 +02:00
Viktor Szakats
f522f10c2f cmake: test integration with old cmake (v3.11.4 2018-03-28)
It was an exercise to run old cmake versions in CI and in the test suite.

It also revealed that 3.7.2 2017-01-13 is too old to consume libssh2 via
`find_package()` due to:
```
CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:35 (add_library):
  add_library cannot create ALIAS target "libssh2::libssh2" because target
  "libssh2::libssh2_shared" is IMPORTED.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)
```
The mitigation for this issue requires 3.11.

Also:
- rename a few existing envs to use the `TEST_` prefix.
- make the `find_package` test provider stage verbose.

Closes #1591
2025-05-08 15:05:07 +02:00
Viktor Szakats
72982d1589 build: sync up picky warnings with curl, fix fallouts
- cmake: sync `-ftree-vrp` behavior with autotools.
- build: enable `-Wjump-misses-init` for GCC 4.5+.
  Credits-to: Marcel Raad
- packet: fix `-Wjump-misses-init` warnings.
  ```
  src/packet.c: In function ‘_libssh2_packet_add’:
  src/packet.c:671:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:920:31: note: ‘want_reply’ declared here
  src/packet.c:671:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:919:26: note: ‘len’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1121:31: note: ‘want_reply’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1120:26: note: ‘len’ declared here
  src/packet.c:669:9: error: jump skips variable initialization [-Werror=jump-misses-init]
  src/packet.c:1119:26: note: ‘channel’ declared here
  ```
- build: enable gcc-12/13+, clang-10+ picky warnings
- acinclude.m4: sync formatting/comments with curl.
- autotools: fix `-Wtrampolines` picky warning for gcc 4.x versions.
  Follow-up to 854cfa8292 #1524
- cmake: enable `-Wall` for MSVC when `PICKY_COMPILER=ON`.
- MSVC: fix `-Wall` warnings.
  Seen on VS2015. Not seen on VS2022. Unknown for other versions.
  ```
  tests\test_simple.c(60): warning C4777: 'fprintf' : format string '%d' requires an argument of type 'int', but variadic argument 1 has type 'std::size_t'
  tests\test_simple.c(60): warning C4777: 'fprintf' : format string '%.*s' requires an argument of type 'int', but variadic argument 2 has type 'std::size_t'
  ```
- mbedtls: stop silencing warnings in 3rd-party header.
  Follow-up to a3aa6b4ca8 #1525
- cmake: stop deleting `-W<n>` from `CMAKE_C_FLAGS` (MSVC)
  1. `CMAKE_C_FLAGS` may apply to other projects, and deleting/altering it
     may be unexpected.
  2. We pass `-W4`/`-Wall` internally now, which do override custom
     `-W<n>` options as tested with VS2008 and newer VS generators.

Closes #1588
2025-05-07 23:24:41 +02:00
Viktor Szakats
62ad6a84ce cmake: honor individual picky option overrides found in CMAKE_C_FLAGS
Also to sync up with similar `./configure` feature via
`CURL_ADD_COMPILER_WARNINGS()`.

Example: `-DCMAKE_C_FLAGS=-Wno-xor-used-as-pow`

It may be useful as a workaround if a specific build combination hits
a picky warning within libssh2's source code. If such happens, we do
appreciate a report to fix it in libssh2 itself.

Closes #1590
2025-05-07 23:22:16 +02:00
Viktor Szakats
f89406b50c Dockerfile: switch to Debian stable
To avoid failing tests in job
'linux (clang, i386, Libgcrypt, autotools, ON, --disable-static)'.
Same job with x86_64 or OpenSSL did pass without issues.

Example:
https://github.com/libssh2/libssh2/actions/runs/14703383105/job/41758988183?pr=1588
```
libssh2_session_handshake failed (-5): Unable to exchange encryption keys
```

Bug: https://github.com/libssh2/libssh2/pull/1591#issuecomment-2844417405
Fix-suggested-by: Jacob Barthelmeh
Fixes #1594
Closes #1595
2025-05-07 01:04:57 +02:00
Viktor Szakats
4e78006c2b cmake: fix copy-paste typo in integration tests for old cmake
Follow-up to 77df767784 #1589

Closes #1592
2025-04-28 15:04:28 +02:00
Viktor Szakats
77df767784 cmake: extend integration tests
- ci/GHA: add cmake integration tests for Windows.
- ci/GHA: test `add_subdirectory` with Libgcrypt.
- make them run faster with prefill, unity, Ninja, omitting curl tool.
- add support for any build configuration.
- add old-cmake support with auto-detection.
- auto-detect Ninja.
- run consumer test apps to see if they work.
  Also show the cryptography backend.
- add support for Windows.
- make it more verbose.
- re-add `ExternalProject` cmake consumer test. It's broken.
- tidy up terminology.

Cherry-picked from #1581

Closes #1589
2025-04-27 13:46:30 +02:00
Viktor Szakats
ac80041852 cmake: IMPORTED target improvements and fixes
- fix `add_subdirectory` builds for old CMake versions.
- libssh2-config.cmake: fix to set CMP0099 for CMake 3.17+ only.
- libssh2-config.cmake: generalize code to support any number of deps.
  (mainly to sync with curl.)
- libssh2-config.cmake: bind dependencies to the static libssh2 only.

Follow-up to a0d8529b08 #1571
Follow-up to df0563a857 #1535

Closes #1581
2025-04-27 13:46:30 +02:00