1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-01-27 00:18:12 +03:00
Commit Graph

3029 Commits

Author SHA1 Message Date
Viktor Szakats
01b8d3565e ci/GHA: skip updating man-db for faster installs (Ubuntu)
To save 5+ seconds per CI job.

Also drop `/etc/apt/sources.list.d/microsoft-prod.list`.

Closes #1584
2025-04-25 14:37:00 +02:00
Viktor Szakats
6af8a7ca7f cmake: use CMAKE_COMPILE_WARNING_AS_ERROR if available
It's available in CMake >= 3.24.

Ref: https://cmake.org/cmake/help/latest/variable/CMAKE_COMPILE_WARNING_AS_ERROR.html

Closes #1583
2025-04-25 14:37:00 +02:00
Viktor Szakats
7b4f821e7a cmake: fix declspec for MSVC consuming static libssh2
Ref, same fix in curl (2018-08-15):
ab66a80488
https://github.com/curl/curl/issues/2817
https://github.com/curl/curl/pull/2823

Reported-by: geral-victor on github
Fixes #1578
Closes #1579
2025-04-22 08:56:11 +02:00
Viktor Szakats
8a871d0b40 cmake: tidy-up ENABLE_WERROR logic
Tidy up the way we handle options not to be passed to feature checks,
and make sure to show them in the configure log.

Also:
- drop redundant and obsolete compiler check.
- drop redundant parenthesis.

Closes #1576
2025-04-15 16:18:44 +02:00
Viktor Szakats
a8e4456b05 cmake: avoid passing options via CMAKE_*_FLAGS
- replace `CMAKE_C_FLAGS*` and `CMAKE_CXX_FLAGS` with `COMPILE_OPTIONS`.
- replace `CMAKE_SHARED_LINKER_FLAGS_DEBUG` with
  `LINK_OPTIONS`/`LINK_FLAGS`.
- make it explicit to pass these C flags to feature checks.
- enable `-pedantic-errors` picky option for GCC with CMake <3.23.
- drop redundant condition when stripping existing MSVC `/Wn` options.

CMake passes `CMAKE_C_FLAGS` to targets, feature checks and raw
`try_compile()` calls. With `COMPILE_OPTIONS`, this is limited to
targets, and we must explicitly pass them to feature checks. This
makes the build logic clearer, and offers more control. It also
reduces log noise by omitting these options from linker commands,
and from `CMAKE_C_FLAGS` dumps in feature checks.

Closes #1575
2025-04-15 01:47:31 +02:00
Viktor Szakats
a0d8529b08 cmake: fix target interfaces for old CMake versions
- drop `VERSION` target property for cmake <3.19 compatibility
  ```
  CMake Error at CMake/Find*.cmake:90 (set_target_properties):
    INTERFACE_LIBRARY targets may only have whitelisted properties.
    The property "VERSION" is not allowed.
  ```
- move custom target property to the `INTERFACE_` namespace
  for cmake <3.19 compatibility. (To avoid same error as above)
- fix forwarding multiple `CFLAGS`, when detected via `pkg-config`.
- restore support for `-framework` and raw libs when processing
  the internal lib list for generating `libssh2.pc`. For good measure,
  at the moment libssh2 doesn't depend on a Framework.
- limit `libssh2_dumptargetprops()` to cmake 3.19+. It doesn't work with
  older versions.

Issues found while applying this change to curl. They did not surface in
libssh2 CI.

Follow-up to df0563a857 #1535

Closes #1571
2025-04-14 02:13:37 +02:00
Viktor Szakats
71179930e1 cmake: use VERSION_GREATER_EQUAL
Available since 3.7, which is the minimum required for libssh2:
https://cmake.org/cmake/help/latest/command/if.html#version-greater-equal

Closes #1573
2025-04-10 08:59:47 +02:00
Viktor Szakats
ea56904aef tests: improve SSHD default value (fixup)
Fix typo in the commit improving `SSHD` default.

Regression from fb12d87e0e #1563

Reported-by: Paul Howarth
Bug: https://github.com/libssh2/libssh2/pull/1563#issuecomment-2753676646

Closes #1568
2025-03-26 11:48:03 +01:00
Viktor Szakats
1323e17ba9 ci/GHA: move Cygwin to drive D: for install speed
Save 30-90s per job in the Cygwin install step.

Closes #1567
2025-03-24 15:26:03 +01:00
Viktor Szakats
fb7ea5d7e1 ci/GHA: add clang-tidy jobs for Linux and Windows
With their supported crypto backends.

Cherry-picked from #1561

Closes #1566
2025-03-24 15:05:31 +01:00
Viktor Szakats
a1a28ac943 clang-tidy: fix and/or silence issues found, and more
- kex: drop unused assigment.
- knownhost: error when salt is NULL.
- mbedtls: avoid unnecessary inline assigments, that were ignored for
  the second block and replaceable with a `ret = 0` initialization for
  the first one.
- mbedtls: fix ignoring an API failure and ending up calling
  `mbedtls_rsa_check_privkey()` unconditionally.
- misc: initialize datalen on error in `_libssh2_base64_decode()`.
- openssl: drop unused assigments.
- openssl: fix unused static function.
- packet: avoid NULL deref.
- packet: avoid NULL in `memcpy` src.
- publickey: optimize struct layout to avoid padding.
- sftp: replace ignored `rc` error assigment with `_libssh2_error()` call.
- transport: fix potential NULL ptr dereferences.
- transport: silence uninitialized value warnings.
- userauth: drop unused assigment.
- userauth: possible use of unitialized pointer.
- userauth: replace `rewind()` with `fseek()`.
  `rewind()` returns an error condition in `errno`. `errno` is
  problematic and reduces portability. Use `fseek()` to avoid it.
- userauth: replace potential NULL deref by returning error from
  `sign_frommemory()`. Possible false positive. `rc` should be set
  upstream if the callback is NULL.
- userauth: replace potential NULL deref by returning error from
  `sign_fromfile()`. clang-tidy did not warn about this one, but
  let's match `sign_frommemory()` anyway.
- wincng: fix potentially unused macros.
- wincng: make sure bignum is not NULL before use.

tests:
- openssh_fixture: drop unused assignment.
- session_fixture: exit if `username` not set, to avoid `strlen(NULL)`.
- session_fixture: replace `rewind()` with `fseek()`.
  `rewind()` returns an error condition in `errno`. `errno` is
  problematic and reduces portability. Use `fseek()` to avoid it.
- test_read: exit if `username` not set, to avoid `strlen(NULL)`.

examples:
- scp_write_nonblock: fix file handle leak.
- sftp_write_nonblock: file handle leak on error.
- sftp_write_sliding: file handle leak on error.
- ssh2_agent_forwarding: fix unused error codes.

Details in the subcommits under the PR.

Thanks-to: Michael Buckley
Thanks-to: Will Cosgrove

Closes #1561
2025-03-24 14:37:08 +01:00
Viktor Szakats
15752e5f0b ci/GHA: sync linux-mingw workflow with curl
To prepare for the addition of a clang-tidy job for Windows.

Cherry-picked from #1561
2025-03-24 14:06:28 +01:00
Viktor Szakats
64fafc78b0 transport: fix formatting
Cherry-picked from #1561
2025-03-24 14:06:28 +01:00
Viktor Szakats
6635880497 cmake: add clang-tidy support via LIBSSH2_CLANG_TIDY=ON
Cherry-picked from #1561
2025-03-24 14:06:24 +01:00
Viktor Szakats
e0681cdba9 build: drop crypto.c umbrella source
Instead build all crypto backend sources always, and exclude inactive
ones with guards.

To play better with code checkers and compilers that are blind to
included C sources, e.g. clang with certain compiler warnings and
clang-tidy.

We continue to include `blowfish.c`.

Follow-up to 4f0f4bff5a #941
Cherry-picked from #1561
2025-03-24 14:04:07 +01:00
Viktor Szakats
ddc4cf34da agent: merge agent_win.c into the main source
To play better with code checkers and compilers that are blind to
included C sources, e.g. clang with certain compiler warnings and
clang-tidy.

Follow-up to 4f0f4bff5a #941
Cherry-picked from #1561
2025-03-24 14:03:56 +01:00
Viktor Szakats
cf15fdd29f tests: use setfacl if available
Closes #1565
2025-03-24 10:07:27 +01:00
Viktor Szakats
902fc9574d cmake: replace deprecated CMAKE_COMPILER_IS_GNUCC
Closes #1564
2025-03-23 21:13:26 +01:00
Viktor Szakats
fb12d87e0e tests: improve SSHD default value
Instead of going for a hardcoded `/usr/sbin/sshd`, use `command -v`
to figure out the default `sshd` executable.

Closes #1563
2025-03-23 21:13:26 +01:00
Viktor Szakats
5930dc3c71 tests: add support for wine/qemu
To run test program via `wine`:
```shell
export LIBSSH2_TEST_EXE_RUNNER=wine
```

It prefixes commands with the specified runner. For systems where this
isn't automatic or supported, e.g. macOS.

Closes #1562
2025-03-23 21:13:25 +01:00
skuodi
6746b78970 mbedtls: Bug fix for gen_publickey_from_rsa (#1560)
Notes:
* Bug fix for gen_publickey_from_rsa
Increment buffer write pointer after writing modulus and after writing exponent.
Add 1 to modulus(bignum) size.

Credit:
skuodi
2025-03-20 13:47:47 -07:00
Viktor Szakats
df0563a857 cmake: make Find modules use INTERFACE
- move dependency properties (libs, libdirs, C flags, header dirs,
  pkg-config module names) from global lists to imported target
  `INTERFACE` properties. Rework FInd modules to return their results
  like this and update the libssh2 build process to use it. It makes
  Find modules re-usable from the cmake-config script by libssh2
  consumers, to integrate with libssh2 dependencies.

- define libssh2 dependencies as "imported targets" by the name:
  `libssh2::<depname>`, e.g. `libssh2::libgcrypt`.

- cmake-config: add fall-back logic for CMake without
  CMP0099 (v3.17 2020-03-20) to set lib directories.

- generate `libssh2.pc` based on imported target properties (instead of
  global lists).

- add target property dump debug function.

- ci/GHA: also test cmake integration on macOS.

Follow-up to 96d7f404e7 #1534

Closes #1535
2025-03-19 18:31:19 +01:00
Viktor Szakats
8ea6ae7213 cmake: add comment to inegration test
To show which command is requiring a specific cmake version.

Follow-up to 7d5a4c7651 #1529
2025-03-19 12:08:32 +01:00
Viktor Szakats
837ccb2d81 cmake: use GREATER_EQUAL
Requires CMake 3.7. Our current minimum.

Closes #1559
2025-03-15 03:12:39 +01:00
Viktor Szakats
94a099bc51 cmake: replace add_definitions() with directory props
To use modern CMake syntax.

Closes #1558
2025-03-15 03:12:38 +01:00
Justin Smith
d32ab16241 ci/GHA: add CI test for AWS-LC
* Adds AWS-LC (cmake, gcc, amd64) to the GitHub CI tests.
* Adds note on how to build w/ BoringSSL or AWS-LC in `INSTALL_CMAKE.md`

AWS-LC recently added CI integration tests for Libssh2 to the AWS-LC
GitHub repo to ensure that we maintain our compatibility with libssh2:
https://github.com/aws/aws-lc/pull/2222

I've verified this change by running the CI job on my fork, which
completed successfully:
https://github.com/justsmth/libssh2/actions/runs/13547314774/job/37862097664

Closes #1557
2025-03-15 03:12:38 +01:00
Viktor Szakats
c03eb8d379 comp: use z_const when zlib supports it
Also switch to zlib-specific types where missing.

Closes #1555
2025-03-11 01:38:17 +01:00
Will Cosgrove
c090b696c6 Session null checks to quiet fuzzer (#1556)
Update session.c. session.h

Make fuzzer happy on `session_startup()` with null session.
2025-03-04 17:11:09 -08:00
oss-patch
1ac1ff4438 kex.c: fix possible null pointer dereference in diffie_hellman_sha_algo() (#1508)
Notes:
PR Description:

Bug Type: Segv on unknown address
Summary: A vulnerability was discovered in the libssh2 program where an invalid memory access occurred due to dereferencing a NULL pointer. The issue was identified in the diffie_hellman_sha_algo function within kex.c.
Fix Summary: The patch resolves the issue by introducing a NULL pointer check for session->hostkey before dereferencing it. If the pointer is NULL, a corresponding error is returned, and the function exits gracefully. This fix ensures the program does not attempt to access invalid memory. The patch improves the security and stability of the program by preventing segmentation faults caused by invalid memory access.
2025-02-28 09:47:47 -08:00
Will Cosgrove
4beed72458 Return error if user KEX methods are invalid #1553 (#1554)
Notes:
Fixes #1553. Restores error case if user passes in invalid KEX method value to libssh2_session_method_pref.

Credit:
Amy Lin
2025-02-28 09:32:30 -08:00
Will Cosgrove
8cad398b0f _libssh2_base64_decode() handle malformed data (#1551)
Make sure to allocate enough space for malformed base64 encoded data.  Changed signed size values to unsigned to match input so we can't possibly truncate input.

Credit:
Stanislav Osipov
2025-02-27 11:46:52 -08:00
Will Cosgrove
2fb5803ce1 Fix possible double free if key in error cases (#1550)
Notes:
Fix possible double free of key in certain error cases. #1549

Credit:
Stanislav Osipov
2025-02-26 10:07:33 -08:00
Viktor Szakats
669b51a076 cmake: prefer CMAKE_INSTALL_PREFIX over --prefix (in tests)
Closes #1542
2025-02-17 18:43:49 +01:00
Viktor Szakats
a751d578be tidy-up: replace exit() with return
In examples and the manual page for `libssh2_version()`.

Closes #1541
2025-02-13 13:51:49 +01:00
Viktor Szakats
9642a96ef7 cmake: add missing quotes
For consistent initialization for `_sys_libdirs` and just for consistent
formatting in the other case.

Ref: https://github.com/curl/curl/pull/16233#issuecomment-2642603412
Follow-up to 3de8731ef2 #1540
2025-02-07 12:58:02 +01:00
Viktor Szakats
3de8731ef2 cmake: exclude CMAKE_C_IMPLICIT_LINK_DIRECTORIES from libssh2.pc
Co-authored-by: Kai Pastor
Ref: f72b848092
Ref: https://github.com/curl/curl/pull/16233
2025-02-07 12:01:35 +01:00
Viktor Szakats
d92de5951a cmake: initialize variables where missing
As detected using `cmake --warn-uninitialized`.

It also lists documented CMake global variables, which is unexpected:
`CMAKE_MODULE_PATH`, `CMAKE_IMPORT_LIBRARY_SUFFIX`.
I'd expect CMake to initialize its namespace.

https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-warn-uninitialized

Closes #1539
2025-02-06 03:43:37 +01:00
Viktor Szakats
9da0ca3cde cmake: normalize before matching paths with syspaths
Requires CMake 3.20:
https://cmake.org/cmake/help/latest/command/cmake_path.html

Co-authored-by: Kai Pastor
Ref: 307e1f9878
Closes #1538
2025-02-06 01:11:04 +01:00
Viktor Szakats
eea97dbf0a cmake: ZLIB linkage tidy-ups
- drop adding redundant ZLIB manual include headers.
  It's done now via `ZLIB::ZLIB`.
  Follow-up to 96d7f404e7 #1534

- src: replace missed `ZLIB_LIBRARIES` with `ZLIB::ZLIB`.
  Follow-up to 96d7f404e7 #1534

- src: drop always true `ZLIB_FOUND` check.

Cherry-picked from #1535
2025-02-05 12:47:23 +01:00
Viktor Szakats
d07d12ae07 cmake: extend, not overwrite, CMAKE_REQUIRED_* values
Make sure to keep any previously added settings. For good measure;
this hasn't been an issue with libssh2 builds yet.

Cherry-picked from #1535
2025-02-05 12:40:40 +01:00
Viktor Szakats
1a9f7b4cdd cmake: avoid dupe target_link_libraries() commands in tests
Cherry-picked from #1535
2025-02-05 12:39:37 +01:00
Viktor Szakats
5f51c7a21a ci/GHA: limit ENABLE_ECDSA_WINCNG option to WinCNG
To avoid cmake warning:
```
CMake Warning:
  Manually-specified variables were not used by the project:

    ENABLE_ECDSA_WINCNG
```
https://github.com/libssh2/libssh2/actions/runs/13126062299/job/36622533686?pr=1535#step:3:88

Follow-up to 3f98bfb090 #1368
Cherry-picked from #1535
2025-02-05 12:37:22 +01:00
Viktor Szakats
96d7f404e7 cmake: make libssh2-config work with all TLS-backends
CMake:

- Find*: set `<modulename>_FOUND` for compatibility when found via
  `pkg-config`. E.g. `MbedTLS_FOUND`.
  `find_package_handle_standard_args()` sets both `<MODULENAME>_FOUND`
  and `<Modulename>_FOUND` when detecting the dependency. Some CMake
  code relies on this and 3rd-party code may rely on it too. Make sure
  to set the latter variant when detecting the dependency via
  `pkg-config`, where we don't call
  `find_package_handle_standard_args()`.

  CMake sets these variable to `TRUE` (not `ON` or `1`). Replicate this
  for compatibility.

- libssh2-config.cmake: inherit default `LIBSSH2_USE_PKGCONFIG`.
  Follow-up to a3aa6b4ca8 #1525

- document variables consumed by `libssh2-config.cmake.in`.

- `libssh2-config.cmake`: fix to link to non-OpenSSL crypto backends.
  This is most likely not how this is supposed to be done, but better
  than failing.
  What's the canonical way to do this, and how OpenSSL and zlib does it
  is yet to be figured out.

- use `ZLIB::ZLIB` to reference zlib.
- use `IN ITEMS` where missed.
- harmonize variable dump output formats.

CMake `find_package` integration tests:

- extend to all crypto backends (was: OpenSSL).
- show libssh2 variables set by `find_package()`.
- stop building examples and tests for the consumed package.
  For performance.
- enable zlib, for coverage.
- be verbose when building the test targets.

ci/GHA:

- add packaged mbedTLS (2.x) build to Linux matrix.
- alphasort some tests.

Follow-up to d9c2e550ca #1460
Follow-up to 82b09f9b3a #1322

Closes #1534
2025-02-04 00:39:38 +01:00
Viktor Szakats
d033c1eaf6 cmake: tidy up string append and list prepend syntax
- `set(VAR "${VAR}<value>")` ->
  `string(APPEND VAR "<value>")`
  Available since CMake 3.4:
  https://cmake.org/cmake/help/latest/command/string.html#append

- `set(VAR "${VAR2}-or-<value>;${VAR}")` ->
  `set(VAR "${VAR2}-or-<value>" ${VAR})`

- prefer dash-style MSVC option.
  Follow-up to 854cfa8292 #1524

Closes #1533
2025-02-02 02:57:52 +01:00
Viktor Szakats
b89858b83d disable deprecated algos by default
- MD5-based MACs and hashes: `hmac-md5`, `hmac-md5-96`,
  `LIBSSH2_HOSTKEY_HASH_MD5`
    You can enable it now with `-DLIBSSH2_MD5_ENABLE`.
    Disabled by default since OpenSSH 7.2 (2016-02-29).
- 3DES cipher: `3des-cbc`
    You can enable it now with `-DLIBSSH2_3DES_ENABLE`.
    Disabled by default since OpenSSH 7.4 (2016-12-19).
- RIPEMD-160 MACs: `hmac-ripemd160`, `hmac-ripemd160@openssh.com`
    You can enable it now with `-DLIBSSH2_HMAC_RIPEMD_ENABLE`.
    Removed in OpenSSH 7.6 (2017-10-03).
- Blowfish cipher: `blowfish-cbc`
    You can enable it now with `-DLIBSSH2_BLOWFISH_ENABLE`.
    Removed in OpenSSH 7.6 (2017-10-03).
- RC4 ciphers: `arcfour`, `arcfour128`
    You can enable it now with `-DLIBSSH2_RC4_ENABLE`.
    Removed in OpenSSH 7.6 (2017-10-03).
- CAST cipher: `cast128-cbc`
    You can enable it now with `-DLIBSSH2_CAST_ENABLE`.
    Removed in OpenSSH 7.6 (2017-10-03).

- old-style, MD5-based encrypted private keys.
    You can enable it now with `-DLIBSSH2_MD5_PEM_ENABLE`.

CI runs:
before:
https://github.com/libssh2/libssh2/actions/runs/13066267976/job/36459081012
https://ci.appveyor.com/project/libssh2org/libssh2/builds/51426618
after:
https://github.com/libssh2/libssh2/actions/runs/13071320635/job/36473418776?pr=1531
https://ci.appveyor.com/project/libssh2org/libssh2/builds/51428270

Closes #1531
2025-01-31 13:04:33 +01:00
Viktor Szakats
5cca650b1d tidy-up: prefer #ifdef / #ifndef (formatting)
Closes #1532
2025-01-31 13:04:32 +01:00
Viktor Szakats
784446b6c5 build: add support for clang-cl, add CI job
- ci/appveyor: add clang-cl job.
- ci/appvayor: optimize setting an env.
- build: fix clang-cl builds.
- build: fix `-Wcast-function-type` compiler warnings for OpenSSL 3.
- build: use `stdint.h` with MSVC when supported.
- src: use `PRId64` for MSVC where supported.
- src: avoid recursive macro definition for `recv()` and `send()`.
- session: silence `-Wcast-function-type` for `libssh2_session_callback_set2()`.
  Sadly this function is still not fully warning-clean, and it
  seems we'd need separate setter-getters for each callback
  to avoid all warnings.

Closes #1484
2025-01-31 05:13:18 +01:00
Viktor Szakats
6443b2f9d0 ci/GHA: bump BoringSSL
Also replace manual `-fPIC` C flag with
`-DCMAKE_POSITION_INDEPENDENT_CODE=ON`. It makes it pass it to C++,
which is necessary for BoringSSL after this bump.

Fixes:
```
/usr/bin/ld: /home/runner/usr/lib/libcrypto.a(crypto.cc.o): warning: relocation against `stderr@@GLIBC_2.2.5' in read-only section `.text'
/usr/bin/ld: /home/runner/usr/lib/libcrypto.a(urandom.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
```
https://github.com/libssh2/libssh2/actions/runs/13065421829/job/36456862458#step:27:23

Closes #1530
2025-01-31 04:19:26 +01:00
Viktor Szakats
7d5a4c7651 cmake: split integration tests into steps
Closes #1529
2025-01-31 04:19:25 +01:00
Viktor Szakats
131480d2d5 wincng: move _libssh2_aes_ctr_increment() from misc, make static
Cherry-picked from #1484
2025-01-31 02:07:08 +01:00