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

2975 Commits

Author SHA1 Message Date
Viktor Szakats
2da28146a0 openssl: make it compatible with wolfSSL built without OPENSSL_ALL
Cherry-picked from #1484
2025-01-31 01:50:15 +01:00
Viktor Szakats
008e82c0f8 ci/GHA: general maintenance, security, add LibreSSL and old OpenSSL jobs with tests
- add Linux jobs with old OpenSSL versions: 1.1.1, 1.1.0, 1.0.2, with
  tests.
  (Meaning we test these again after losing them in AppVeyor CI)
- add LibreSSL Linux job with tests.
- cache most dependency packages built from source.
  (exception: wolfSSL, which would have added too much complexity
  due to the multiple versions, and it's fast to build anyway.)
- change source tarball sources to GitHub for better stability and
  performance.
- move dependency versions to the env.
- set `persist-credentials: false` for checkout steps for security.
- pin actions to hash for security.
- checkout repo later, right before use.
- skip building BoringSSL tests to finish quicker.
- set `fail-fast: false` in the BSD build matrix.
- cmake: move UWP workaround from GHA to `CMakeLists.txt`, making it
  available for everyone.
- list installed packages in OpenBSD job.
- bump BoringSSL, mbedTLS, wolfSSL, OpenSSL.
- bump cross-platform-actions to v0.26.
- bump docker/build-push-action to v6.
- bump actions/upload-artifact to v4.
- bump NetBSD to 10.1.
- drop `--quiet 2` `apt-get` option to keep useful output.
- drop `--no-install-suggests --no-install-recommends` `apt-get`
  options. They are the defaults with the `ubuntu-24.04` image.
- tidy up quotes.

Cherry-picked from #1484

Closes #1528
2025-01-31 01:48:39 +01:00
Viktor Szakats
606c102e52 build: enable -Wcast-qual, fix fallouts
- enable compiler warning `-Wcast-qual`.
- add `LIBSSH2_UNCONST()` macro to strip const where absolutely
  necessary to avoid compiler warnings.
- fix const stripping by constifying where necessary.
- fix const stripping by using `LIBSSH2_UNCONST()`.
- libgcrypt.h: drop unnecessary casts.
- openssl: fix to use new `BIO_new_mem_buf()` parameter types
  with wolfSSL.

Cherry-picked from #1484
Closes #1527
2025-01-31 00:57:26 +01:00
Viktor Szakats
96cbe61896 ossfuzz: fix picky compiler warnings, make it pass checksrc
- fix compiler warnings.
- make it pass `checksrc`.
- fix shell `set -u` errors.
  Follow-up to 5012442850 #901
- REUSE: tidy up ossfuzz files.

Cherry-picked from #1484
Closes #1526
2025-01-30 23:36:39 +01:00
Viktor Szakats
a3aa6b4ca8 cmake: misc improvements, add LIBSSH2_USE_PKGCONFIG option
- show platform flags (via curl).
- add `LIBSSH2_USE_PKGCONFIG` option to control whether to use
  `pkg-config` to find dependencies.
- set `.pc` names withing the Find modules.
- add `mbedcrypto` to `libssh2.pc` only when detected via `pkg-config`.
  Workaround for older mbedtls versions and non-CMake mbedTLS builds
  (as of mbedTLS 3.6.2) that don't emit an `mbedcrypto.pc` file.
- set header paths relative to the project root (tidy-up).
- use `-isystem` for crypto backend and zlib header paths.
  To match autotools.
- sync header path order with autotools.
- rename local variables to underscore-lowercase.
- minor tidy-ups.

Cherry-picked from #1484
Closes #1525
2025-01-30 23:36:39 +01:00
Viktor Szakats
854cfa8292 build: prepare builds for clang-cl, add cmake ossfuzz support
- cmake: add support to build ossfuzz.
  Enable with `-DBUILD_OSSFUZZ=ON`.
  Also supports `-DLIB_FUZZING_ENGINE=` like autotools does.
- check for `__clang__` when suppressing warnings in source. Necessary
  for clang-cl, which set `__clang__`, but doesn't set `__GNU__`.
- cmake: optimize out 4 picky warning option detections with gcc.
- cmake: bring `-pedantic-error`, `-Wall` use closer to curl's.
- cmake: set `-Wno-language-extension-token` for clang-cl.
- cmake: escape only the necessary `-W` options for clang-cl.
- cmake: apply picky warnings to C++.
- cmake: replace `unset(VAR)` with `set(VAR "")` for init.
- cmake: prefer dash-style MSVC options.
- cmake: simplify `MATCHES` expression.
- cmake: formatting/whitespace.
- ci/GHA: bump `actions/upload-artifact` to v4

Closes #1524
2025-01-30 22:01:49 +01:00
Viktor Szakats
af5c9fb88f openssl: fix indentation 2025-01-29 19:00:51 +01:00
Viktor Szakats
1612807b9f cmake: make integration tests generator-agnostic, use GIT_SHALLOW
Closes #1523
2025-01-29 14:02:48 +01:00
Viktor Szakats
717c083653 cmake: bump policy_max, add FATAL_ERROR for old cmake versions
Closes #1510
2025-01-29 13:02:40 +01:00
Viktor Szakats
8011f9017b tests: delete CMake ExternalProject integration test
For no reason it broke when trying to silence a CMake deprecation
warning in #1510. Then when tested locally, it did not work either with
or without the patch in #1510.

I'm not sure, but existing implementation may have worked by accident
by re-using leftovers from the preceding two integration tests.

After spending a days trying to fix this, I declare defeat. If such
amount of time of testing, reading documentation, blog posts, variable
traces, logs, bug reports is not enough to make this work, or even
to understand how this should work, this seems like a lost cause.

CMake makes it impossible to cleanly query the properties of a target,
which would be essential for debugging. There are rough workarounds
with years of iteration, and those still don't work to this day:
https://stackoverflow.com/questions/32183975/how-to-print-all-the-properties-of-a-target-in-cmake

Copy-pasting an incantation from a blog post that made this work:
https://inhzus.io/posts/2023-12-01-cmake-external-project/
almost made it work, except that it had a workaround for a 10-year old
pending bug, another workaround for Ninja which required CMake 3.29,
with settings hard-wired, and explicitly configured in weird ways. But,
it still missed to pass the libssh2 library to the test target and
failed to link.

Then tried to pass the libssh2 lib the "usual" way via:
```
target_link_libraries(test PRIVATE libssh2)
```

That also did not work because CMake decided that the external libssh2
target is of "UTILITY" type, and errored with:
```
CMake Error at CMakeLists.txt:39 (target_link_libraries):
  Target "libssh2" of type UTILITY may not be linked into another target.
  One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.
```

This type property is read-only, and documentation has no mention of it,
or how to set it whatsoever:
https://cmake.org/cmake/help/latest/module/ExternalProject.html

libssh2's `docs/INSTALL_CMAKE.md` mentions ExternalProject as a way to
use libssh2. Added there with the initial CMake commit. We should
probably delete it from there.

This consumption method has a single mention in public issues:
https://github.com/libssh2/libssh2/issues/1116

Closes #1522
2025-01-29 12:45:07 +01:00
Will Cosgrove
7495084b1c libssh2_trace.3: Update prototype
Return value is int, not void.

Reported-by: pyscripter on github
Bug: https://github.com/libssh2/libssh2/issues/1517#issuecomment-2608628918
Closes #1518
2025-01-29 02:55:02 +01:00
Viktor Szakats
c343f06b38 mansyntax.sh: revert a change to unhide man error output
Reverts part of 2213352758 #982
2025-01-29 02:49:22 +01:00
Viktor Szakats
d65c4b3987 ci/GHA: fix Cygwin breakage in mansyntax.sh
Cygwin CI jobs started failing while running `mansyntax.sh`.

The reason for the fallout is `util-linux` packaged by Cygwin no
longer shipping `col.exe`, that is required by `man.exe`:
https://cygwin.com/packages/x86_64/util-linux/util-linux-2.39.3-2 (2024-04-02)
https://cygwin.com/packages/x86_64/util-linux/util-linux-2.40.2-1 (2024-12-24)

Work it around by telling `man` to not call `col`.

Relevant links:
https://github.com/util-linux/util-linux
https://gitlab.com/man-db/man-db
https://cygwin.com/packages/summary/util-linux.html
https://cygwin.com/cgit/cygwin-packages/util-linux/log/ (no visible commit for 2.40.2-1)
https://cygwin.com/pipermail/cygwin/2025-January/date.html (no reports)

Fixes:
```
test 1
    Start 1: mansyntax

1: Test command: /usr/bin/sh.exe "-c" "/cygdrive/d/a/libssh2/libssh2/tests/mansyntax.sh"
1: Working Directory: /cygdrive/d/a/libssh2/libssh2/bld/tests
1: Test timeout computed to be: 10000000
1: /cygdrive/d/a/libssh2/libssh2/tests/../docs/libssh2_agent_connect.3
1: man: can't execute col: No such file or directory
1: man: command exited with status 127: col -b -p -x | sed -e '/^[[:space:]]*$/{ N; /^[[:space:]]*\n[[:space:]]*$/D; }'
1/2 Test #1: mansyntax ........................***Failed    0.24 sec
/cygdrive/d/a/libssh2/libssh2/tests/../docs/libssh2_agent_connect.3
man: can't execute col: No such file or directory
man: command exited with status 127: col -b -p -x | sed -e '/^[[:space:]]*$/{ N; /^[[:space:]]*\n[[:space:]]*$/D; }'
```
https://github.com/libssh2/libssh2/actions/runs/13021305834/job/36322366102?pr=1510#step:6:216

Closes #1521
2025-01-29 02:43:41 +01:00
Will Cosgrove
73ac65f79b userauth.c: fix typo from #1516
When making style fixes I inverted the NULL check logic.
2025-01-23 08:06:25 -08:00
Will Cosgrove
49837fd756 userauth.c: fix possible memory leaks #1504 (#1516)
* userauth.c: fix possible memory leaks #1504

Notes:
Fix possible memory leaks if `userauth_list()` is called more than once, e.g. an auth error case. 

Author:
Will Cosgrove

Credit:
pyscripter
2025-01-22 16:53:14 -08:00
Viktor Szakats
df2b206cd0 ci/appveyor: fix PowerShell warning (#1514)
in WinCNG builds, e.g. VS2015, WinCNG, x86, Server 2016:
```
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At line:10 char:16
+   if(Test-Path $env:OPENSSL_ROOT_DIR) {
+                ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
```
https://ci.appveyor.com/project/libssh2org/libssh2/builds/51280178/job/9ddtkb91w54si3da#L85
2025-01-07 20:11:55 +01:00
Viktor Szakats
25d3a09207 ci/appveyor: use -A option with all MSVC versions (#1513)
To simplify the initialization. The ` Win64` method was meant for old
CMake versions not in use in CI.

Also pass the `-A` option without a space to make PowerShell pass
the option as expected by CMake.
2025-01-07 18:36:50 +01:00
Viktor Szakats
bc78138371 ci/GHA: bump to cygwin v5 (#1512) 2025-01-07 11:09:33 +01:00
Viktor Szakats
4725826550 cmake: fix cmake warnings (#1511)
```
CMake Warning (dev) at cmake/CopyRuntimeDependencies.cmake:59 (add_custom_command):
  The following keywords are not supported when using
  add_custom_command(TARGET): DEPENDS.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.
  Run "cmake --help-policy CMP0175" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  example/CMakeLists.txt:58 (add_target_to_copy_dependencies)
```
```
CMake Warning (dev) at cmake/CopyRuntimeDependencies.cmake:59 (add_custom_command):
  Exactly one of PRE_BUILD, PRE_LINK, or POST_BUILD must be given.  Assuming
  POST_BUILD to preserve backward compatibility.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.
  Run "cmake --help-policy CMP0175" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  example/CMakeLists.txt:58 (add_target_to_copy_dependencies)
```
Ref: https://github.com/libssh2/libssh2/actions/runs/12614228505/job/35152908184?pr=1510#step:15:77
2025-01-05 00:48:55 +01:00
Viktor Szakats
389d70bfeb cmake: tidy up -j make option in integration tests (#1509) 2025-01-04 23:24:51 +01:00
Viktor Szakats
ffd0c982a5 configure: fix --without-lib*-prefix when lib* is detected anyway
Do not test the prefix when set to `no`.
(as with `--without-lib*-prefix`)

Before this patch this test was always made and when detected despite
the wrong prefix, the `no` prefix remained in `LDFLAGS` causing a build
failure later in `libtool`.

Fixes:
```
$ ../configure --without-libssl-prefix
[...]
../libtool: line 7756: cd: no/lib: No such file or directory
libtool:   error: cannot determine absolute directory name of 'no/lib'
make[2]: *** [libssh2.la] Error 1
```

Follow-up to d19b619070 #1384

Reported-by: Christoph Reiter
Fixes #1505
Closes #1506
2025-01-02 22:34:21 +01:00
Viktor Szakats
bd8caa1983 configure: drop duplicate -lmbedcrypto from LIBS
Closes #1507
2025-01-02 14:19:44 +01:00
Stephan Eggermont
780bf13aa2 libssh2.h: typo fixes
Closes #1496
2024-11-21 11:46:26 +01:00
Viktor Szakats
21228cffb8 transport: fix indentation of comments
Cherry-picked from #1484
2024-11-15 01:55:18 +01:00
Viktor Szakats
c78d54c28e transport: stop passing newline to the trace handler via debugdump()
The trace handler is called from two places in libssh2. One of them was
passing a newline at the end of the trace message string, the other one
was not.

When the trace handler feature was introduced, a newline was passed both
via `debugdump()` and `libssh2_debug()`:
44eba0c993 (2010-01-15)

Shortly after a commit deleted the newline for `libssh2_debug()`:
0f0652a309 (2010-06-23)

This patch re-syncs behaviour between the traceback callbacks by
dropping the newline for trace handler calls made from `debugdump()`.

Reported-by: Chris Emsen
Fixes #1485
Follow-up to 0f0652a309
Closes #1492
2024-11-14 20:00:14 +01:00
Viktor Szakats
114923f1ac tidy-up: unsigned const char -> const unsigned char
For consistency with rest of the code.

Closes #1487
2024-11-02 00:37:59 +01:00
Viktor Szakats
91b0e09934 tidy-up: spelling [ci skip] 2024-10-31 21:19:43 +01:00
Viktor Szakats
5d03b4f94a cmake: build but don't install static lib in certain conditions
Building 3 tests require static libssh2 lib. Some may prefer not to
create the static lib, yet prefer to build all tests, including those
3 that require it.

Detect such intent by looking for an explicit `BUILD_TESTING=ON` and
`BUILD_STATIC_LIBS=OFF`, then build the static lib anyway but without
installing it.

Reported-by: Eli Schwartz
Fixes #1450
Closes #1469
2024-10-28 21:10:32 +01:00
Viktor Szakats
4844e36840 build: disable warning -Wunreachable-code-break
This warning remains silent in unity builds. Since we're using unity
in CI for most jobs, warnings remain undetected there.
Disable them for all builds to avoid a surprise warning outside our CI.

It also doesn't work in any #included `.c` sources, like the crypto
backend sources.

The issue caught by the warning is useful for a tidy codebase, but
doesn't affect executed code. It was enabled in
84338c4de2d7c798e3c270c9610d51a4ad18a90b #12331 (2023-11-15).

llvm source: fee2953f23/clang/lib/Sema/AnalysisBasedWarnings.cpp (L125-L134)
llvm issue: https://github.com/llvm/llvm-project/issues/71046

Follow-up to 7ecc309cd1 #1224
Closes #1481
2024-10-28 12:30:02 +01:00
Viktor Szakats
bf9bb04571 cmake: add clang-cl support to PickyWarnings.cmake
via curl. (Untested with clang-cl in libssh2.)

Closes #1480
2024-10-28 12:30:02 +01:00
Viktor Szakats
d4e43c7b69 cmake/Find*: clear package version after pkg-config detection
`pkg_check_modules()` seems to leave `<PACKAGE>_VERSION` defined with an
empty value, if the package is not found.

When the package is also not found in the fallback branch,
`find_package_handle_standard_args()` logs and error message. In this
message it includes the bogus empty value as: `(found version "")`:
```
  Could NOT find Libgcrypt (missing: LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)
  (found version "")
```

Clear the version number to avoid the confusion:
```
  Could NOT find Libgcrypt (missing: LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)
```

Seen with CMake v3.30.3 and 3.30.5.

Closes #1479
2024-10-28 11:35:41 +01:00
Viktor Szakats
ac00f6c437 cmake: tidy up variables names in PickyWarnings.cmake
Use underscore-lowercase for internal variables to match the rest of
the source.

Closes #1478
2024-10-28 11:35:41 +01:00
Viktor Szakats
efad5f9076 cmake: decorate comments in Find modules
Make them Markdown-like and make them pass spellcheckers better.

Closes #1477
2024-10-28 11:35:40 +01:00
Viktor Szakats
d01680ca09 ci/GHA: make apg-get install faster, drop a workaround
- always pass `--no-install-suggests --no-install-recommends`
  to `apt-get` to avoid spending time to install packages we don't need.
  (notably in the i386 Linux job.)

- drop an `apt-get` hack that's no longer necessary.

Closes #1476
2024-10-23 01:15:07 +02:00
Pascal Neuperger
83590ac70d libssh2.h: add note about release versions to LIBSSH2_VERSION
As noted in #771 and #1473, the blessed and signed releases are on
libssh2.org and any other archives, like those generated by GitHub,
are just a collection of files from the tag and are not the official
releases.

This adds a note, which already exists for `LIBSSH2_TIMESTAMP`, to
`LIBSSH2_VERSION`, to clarify this fact.

Closes #1475
2024-10-23 01:15:07 +02:00
Viktor Szakats
7e1c6be12f checksrc: sync with curl
Check spaces around logical AND operator.

Closes #1474
2024-10-21 23:34:23 +02:00
Viktor Szakats
c04d57e785 libssh2.h: bump to 1.11.2_DEV 2024-10-21 12:00:17 +02:00
Viktor Szakats
00e5975ad2 libssh2.h: bump to 1.11.1 2024-10-21 11:59:53 +02:00
Viktor Szakats
9d6836e098 ci/GHA: adjust job for Ubuntu 24.04 image
Closes #1470
2024-10-21 11:55:29 +02:00
Daniel Stenberg
a312b43325 RELEASE-NOTES: 1.11.1 libssh2-1.11.1 2024-10-16 10:03:11 +02:00
Viktor Szakats
e2b2c02686 RELEASE-NOTES: sync [ci skip] 2024-10-08 23:08:39 +02:00
Anders Borum
1a9e8811f7 session: support server banners up to 8192 bytes (was: 256)
If server had banner exceeding 256 bytes there wasn't enough room in
`_LIBSSH2_SESSION.banner_TxRx_banner`. Only the first 256 bytes would be
read making the first packet read fail but also dooming key exchange as
`session->remote.banner` didn't include everything.

This change bumps the banner buffer to 8KB to match OpenSSH.

Fixes #1442
Closes #1443
2024-10-08 23:04:12 +02:00
Viktor Szakats
c3d6729f90 RELEASE-NOTES: sync [ci skip] 2024-10-07 12:15:56 +02:00
Viktor Szakats
45064137ac cmake: sync and improve Find modules, add pkg-config native detection
- sync code between Find modules.
- wolfssl: replace `pkg-config` hints with native detection.
- libgcrypt, mbedtls: add `pkg-config`-based native detection.
- libgcrypt: add version detection.
- limit `pkg-config` use for `UNIX`, vcpkg, and non-cross MinGW builds,
  and builds with no manual customization via `*_INCLUDE_DIR` or
  `*_LIBRARY`.
- replace and sync Find module header comments.
- ci: delete manual mbedTLS config that's now redundant.

Based on similar work done in curl.

Second attempt at #1420
Closes #1445
2024-10-05 20:59:27 +02:00
Viktor Szakats
4b5f6b1031 cmake: initialize LIBSSH2_LIBDIRS [ci skip]
Follow-up to c87f129630 #1466
2024-10-04 13:55:02 +02:00
Viktor Szakats
66f8574ec5 ci/appveyor: fix and bump OpenSSL 3 path, add path check
Follow-up to b5e68bdc37 #1461
Closes #1468
2024-10-04 13:28:04 +02:00
Viktor Szakats
a6d98fb41b cmake: link to OpenSSL::Crypto, not OpenSSL::SSL
Follow-up to 82b09f9b3a #1322
Follow-up to c84745e34e #1128
Cherry-picked from #1445
Closes #1467
2024-10-04 12:58:08 +02:00
Viktor Szakats
c87f129630 cmake: generate LIBSSH2_PC_LIBS_PRIVATE dynamically
Generate `LIBSSH2_PC_LIBS_PRIVATE` from `LIBSSH2_LIBS`.

Also add extra libdirs (`-L`) to `Libs` and `Libs.private`.

Logic copied from curl.

Closes #1466
2024-10-04 11:24:34 +02:00
Viktor Szakats
63898981cc cmake: initialize LIBSSH2_PC_REQUIRES_PRIVATE [ci skip]
Follow-up to 0fce9dcc29 #1464
2024-10-04 02:29:50 +02:00
Viktor Szakats
14b1b9d021 cmake: add comment about ibssh2.pc.in variables [ci skip] 2024-10-04 02:25:15 +02:00