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

2775 Commits

Author SHA1 Message Date
Viktor Szakats
b08cfbc99f ci/gha: review/fixup auto-cancel settings
- use the group expression from `reuse.yml` (via curl).
- add auto-cancel for `ci` and `cifuzz`.
- add auto-cancel to `appveyor_docker`. I'm just guessing here.
  The hope is that it fixes AppVeyor CI runs when re-pushing a PR.
  This frequently caused the freshly pushed session to fail waiting for
  a connection.
- sync group expression in `appveyor_status` with `reuse`.

Closes #1292
2023-12-21 21:41:41 +00:00
Viktor Szakats
b7050d9e0a RELEASE-NOTES: fix casing in GitHub names [ci skip] 2023-12-19 16:06:09 +00:00
Viktor Szakats
f0e23dae91 RELEASE-NOTES: synced [ci skip]
Closes #1279
2023-12-19 12:33:45 +00:00
Michael Buckley
d34d9258b8 src: add 'strict KEX' to fix CVE-2023-48795 "Terrapin Attack"
Refs:
https://terrapin-attack.com/
https://seclists.org/oss-sec/2023/q4/292
https://osv.dev/list?ecosystem=&q=CVE-2023-48795
https://github.com/advisories/GHSA-45x7-px36-x8w8
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-48795

Fixes #1290
Closes #1291
2023-12-19 12:25:36 +00:00
Viktor Szakats
c0f69548be session: add libssh2_session_callback_set2()
Add new `libssh2_session_callback_set2()` API that deprecates
`libssh2_session_callback_set()`.

The new implementation offers the same functionality, but accepts and
returns a generic function pointer (of type `libssh2_cb_generic *`), as
opposed to the old function that used data pointers (`void *`). The new
solution thus avoids data to function (and vice versa) pointer
conversions, which has undefined behaviour in standard C.

About the name: It seems the `*2` suffix was used in the past for
replacement functions for deprecated ones. Let's stick with that.
`*_ex` was preferred for new functions that extend existing ones with
new features.

Closes #1285
2023-12-18 15:02:17 +00:00
Viktor Szakats
3ec53f3ea2 build: enable -pedantic-errors
According to the manual, this isn't the same as `-Werror -pedantic`.
Enable it together with `-Werror`.

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-pedantic-errors-1

This option results in autotools feature detection going into crazies.
To avoid this, we add it to `CFLAGS` late. Idea copied from curl.

This option has an effect only with gcc 5.0 and newer as of this commit.
Let's enable it for clang and older versions too for simplicity. Ref:
d5c0351055
https://github.com/curl/curl/pull/2747

Closes #1286
2023-12-17 15:15:34 +00:00
Viktor Szakats
f8c4579439 build: add mingw-w64 support to LIBSSH2_PRINTF() attribute
And fix the warning it detected.

Closes #1287
2023-12-17 15:12:55 +00:00
Viktor Szakats
9839ebe5e9 libssh2.h: add deprecated function warnings
With deprecated-at versions and suggested replacement function.

It's possible to silence them by defining `LIBSSH2_DISABLE_DEPRECATION`.

Also add depcreated-at versions to documentation, and unify wording.

Ref: https://github.com/libssh2/libssh2/pull/1260#issuecomment-1837017987
Closes #1289
2023-12-16 17:43:02 +00:00
Viktor Szakats
fc24735f61 ci/spellcheck: delete redundant option [ci skip]
`--check-hidden` not necessary when passing filenames explicitly.

Follow-up to a79218d3a0
2023-12-14 20:20:39 +00:00
Viktor Szakats
7010049969 tidy-up: add empty line for clarity [ci skip] 2023-12-14 20:14:55 +00:00
Viktor Szakats
ac68fbe475 build: FIXME -Wsign-conversion to be errors [ci skip] 2023-12-13 06:33:54 +00:00
Viktor Szakats
6e451669ea src: disable -Wsign-conversion warnings, add option to re-enable
To avoid the log noise till we fix those ~360 compiler warnings.

Also add macro `LIBSSH2_WARN_SIGN_CONVERSION` to re-enable them.

Follow-up to afa6b86560 #1257

Closes #1284
2023-12-13 04:39:58 +00:00
Viktor Szakats
0f45dafe5e cmake: fix indentation [ci skip] 2023-12-13 02:41:05 +00:00
Viktor Szakats
94b6bad3c8 example, tests: call WSACleanup() for each WSAStartup()
On Windows.

Closes #1283
2023-12-13 01:28:14 +00:00
Viktor Szakats
52c382f7aa RELEASE-NOTES: update credits [ci skip]
Ref: https://github.com/libssh2/libssh2/pull/1241#issuecomment-1830118584
2023-12-09 21:02:27 +00:00
Viktor Szakats
b77504837c RELEASE-NOTES: avoid splitting names, fix typo, refine order [ci skip] 2023-12-09 19:00:31 +00:00
Viktor Szakats
747862c0e2 RELEASE-NOTES: synced [ci skip] 2023-12-09 18:02:06 +00:00
Viktor Szakats
28dbf01667 add portable LIBSSH2_SOCKET_CLOSE() macro
Add `LIBSSH2_SOCKET_CLOSE()` to the public `libssh2.h` header, for user
code. It translates to `closesocket()` on Windows and `close()` on other
platforms.

Use it in example code.

It makes them more readable by reducing the number of `_WIN32` guards.

Closes #1278
2023-12-08 11:19:04 +00:00
Viktor Szakats
46333adfb8 ci: add FreeBSD 14 job, fix issues
- install bash to fix error when running tests:
  ```
  ERROR: test_sshd.test - missing test plan
  ERROR: test_sshd.test - exited with status 127 (command not found?)
  =====================================
  [...]
  # TOTAL: 4
  # PASS:  2
  # SKIP:  0
  # XFAIL: 0
  # FAIL:  0
  # XPASS: 0
  # ERROR: 2
  [...]
  env: bash: No such file or directory
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/7133852508/job/19427420687#step:3:3998

- fix sshd issue when running tests:
  ```
    # sshd log:
    #  Server listening on :: port 4711.
    #  Server listening on 0.0.0.0 port 4711.
    #  Authentication refused: bad ownership or modes for file /home/runner/work/libssh2/libssh2/tests/key_rsa.pub
    #  Authentication refused: bad ownership or modes for file /home/runner/work/libssh2/libssh2/tests/openssh_server/authorized_keys
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/7134629175/job/19429828342#step:3:4059

Cherry-picked from #1277
Closes #1277
2023-12-08 02:04:18 +00:00
Viktor Szakats
5e0ec99134 ci: add OmniOS job, fix issues
- use GNU Make, to avoid errors:
  ```
  make: Fatal error in reader: Makefile, line 983: Badly formed macro assignment
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/7134629175/job/19429838379#step:3:1956

  Caused by `?=` in `Makefile.am`. Fix it just in case.

  ```
  make: Fatal error in reader: Makefile, line 438: Unexpected end of line seen
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/7135524843/job/19432451767#step:3:1966

  It's around line 43 in `Makefile.am`, reason undiscovered.

- fix error:
  ```
  ../../src/hostkey.c:1227:44: error: pointer targets in passing argument 5 of '_libssh2_ed25519_sign' differ in signedness [-Werror=pointer-sign]
     1227 |                                  datavec[0].iov_base, datavec[0].iov_len);
          |                                  ~~~~~~~~~~^~~~~~~~~
          |                                            |
          |                                            caddr_t {aka char *}
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/7135102832/job/19431233967#step:3:2225

  https://docs.oracle.com/cd/E36784_01/html/E36887/iovec-9s.html

- FIXME: new `-Wsign-conversion` warnings appeared in examples:
  ```
  ../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
    251 |         FD_SET(forwardsock, &fds);
        |         ^~~~~~
  ../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
  ../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
  ../../example/direct_tcpip.c:251:9: warning: conversion to 'long int' from 'long unsigned int' may change the sign of the result [-Wsign-conversion]
  ../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
    259 |         if(rc && FD_ISSET(forwardsock, &fds)) {
        |                  ^~~~~~~~
  ../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
  ../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
  [...]
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/7136086865/job/19433997429#step:3:3450

Cherry-picked from #1277
2023-12-08 02:02:44 +00:00
Viktor Szakats
3f60ccb76b example: use libssh2_socket_t in X11 example
Cherry-picked from #1277
2023-12-08 02:01:18 +00:00
Aaron Stone
798ed4a7e5 Handle EINTR from send/recv/poll/select to try again as the error is not fatal
Integration-patches-by: Viktor Szakats
Fixes #955
Closes #1058
2023-12-06 15:46:32 +00:00
Viktor Szakats
d0a7f1da21 appveyor: delete UWP job broken since Visual Studio upgrade
Few days ago UWP job started permafailing.

fail: https://ci.appveyor.com/project/libssh2org/libssh2/builds/48678129/job/yb8n2pox8mfjwv6m
good: https://ci.appveyor.com/project/libssh2org/libssh2/builds/48673013

Other projects also affected:
https://ci.appveyor.com/project/c-ares/c-ares/builds/48687390/job/l0fo4b0sijvqkw9r

No related local update. Same CMake version. Same CI image.

This seems to be the culprit, which could mean that this update broke
CMake detection, needs a different CMake configuration on our end, or
that this MSVC update pulled support for UWP apps:

fail: -- The C compiler identification is MSVC 19.38.33130.0 (~ Visual Studio 2022 v17.8)
good: -- The C compiler identification is MSVC 19.37.32825.0 (~ Visual Studio 2022 v17.7)

If this is v17.8, release notes don't readily suggest a feature removal:
https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.8

So it might just be UWP accidentally broken in this release.

Closes #1275
2023-12-06 14:56:15 +00:00
Viktor Szakats
8cd473c930 checksrc: sync with curl
Closes #1272
2023-12-06 01:13:15 +00:00
Viktor Szakats
e051ae343a autotools: delete --disable-tests option, fix CI tests
Originally added to improve build performance by skipping building
tests. But, there seems to be no point in this, because autotools
doesn't build tests by default, unless explicitly invoking
`make check`.

Delete this option from Cygwin and FreeBSD CI tests, where it caused
`make check` to do nothing. Tests are built now, and runtime tests are
too, where supported.

Also disable Docker-based tests for these, and add a missing `make -j3`
for FreeBSD.

Reverts 7483edfada #715

Closes #1271
2023-12-06 00:55:15 +00:00
ren mingshuai
b1414503f5 build: add LIBSSH2_NO_DEPRECATED option (#1266)
The following APIs have been deprecated for over 10 years and
use `LIBSSH2_NO_DEPRECATED` to mark them as deprecated:

libssh2_session_startup()
libssh2_banner_set()
libssh2_channel_receive_window_adjust()
libssh2_channel_handle_extended_data()
libssh2_scp_recv()

Add these options to disable them:
- autotools: `--disable-deprecated`
- cmake: `-DLIBSSH2_NO_DEPRECATED=ON`
- `CPPFLAGS`: `-DLIBSSH2_NO_DEPRECATED`

Fixes #1259
Replaces #1260
Co-authored-by: Viktor Szakats
Closes #1267
2023-12-06 00:14:53 +01:00
Viktor Szakats
a3f5594a96 autotools: show the default for hidden-symbols option
Closes #1269
2023-12-05 02:14:23 +00:00
Viktor Szakats
2e5a8719d7 tidy-up: bump casts from int to long for large C99 types in printfs
Cast large integer types to avoid dealing with printf masks for
`size_t` and other C99 types. Some of existing code used `int`
for this, bump them to `long`.

Ref: afa6b86560 #1257

Closes #1264
2023-12-04 13:11:28 +00:00
Viktor Szakats
afa6b86560 build: enable missing OpenSSF-recommended warnings, with fixes
Ref:
https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
(2023-11-29)

Enable new warnings:

- replace `-Wno-sign-conversion` with `-Wsign-conversion`.

  Fix them in example, tests and wincng. There remain about 360 of these
  warnings in `src`. Add a TODO item for those and disable `-Werror` for
  this particular warning.

- enable `-Wformat=2` for clang (in both cmake and autotools).

- enable `__attribute__((format))` for `_libssh2_debug()`,
  `_libssh2_snprintf()` and in tests for `run_command()`.

  `LIBSSH2_PRINTF()` copied from `CURL_TEMP_PRINTF()` in curl.

- enable `-Wimplicit-fallthrough`.

- enable `-Wtrampolines`.

Fix them:

- src: replace obsolete fall-through-comments with
  `__attribute__((fallthrough))`.

- wincng: fix `-Wsign-conversion` warnings.

- tests: fix `-Wsign-conversion` warnings.

- example: fix `-Wsign-conversion` warnings.

- src: fix `-Wformat` issues in trace calls.

  Also, where necessary fix `int` and `unsigned char` casts to
  `unsigned int` and adjust printf format strings. These were not
  causing compiler warnings.

  Cast large types to `long` to avoid dealing with printf masks for
  `size_t` and other C99 types. Existing code often used `int` for this.
  I'll update them to `long` in an upcoming commit.

- tests: fix `-Wformat` warning.

- silence `-Wformat-nonliteral` warnings.

- mbedtls: silence `-Wsign-conversion`/`-Warith-conversion`
  in external header.

Closes #1257
2023-12-03 01:32:20 +00:00
Viktor Szakats
e0a0466490 packet: whitespace fix
Tested via #1257
2023-12-02 22:31:12 +00:00
Viktor Szakats
b136c37998 tidy-up: unsigned -> unsigned int
In the `interval` argument of public `libssh2_keepalive_config()`.

Tested via #1257
2023-12-02 09:53:56 +00:00
Viktor Szakats
eb996af851 tests: sync port number type with the rest of codebase
Tested via #1257
2023-12-02 09:53:55 +00:00
Viktor Szakats
ecdf519911 autotools: enable -Wunused-macros with gcc
It works with gcc without the libtool warnings seen with clang
on Windows in 96682bd5e1 #1227.

Sync usage of of this macro with CMake and
autotools + clang + non-Windows. Making it enabled everywhere except
autotools + clang + Windows due to the libtool stub issue.

Follow-up to 7ecc309cd1 #1224

Closes #1262
2023-12-02 09:51:59 +00:00
Viktor Szakats
0b4bdc856f TODO: disable or drop weak algos [ci skip]
Closes #1261
2023-12-02 08:29:49 +00:00
Viktor Szakats
744e059f31 example, tests: fix/silence -Wformat-truncation=2 gcc warnings
Then sync this warning option with curl.

Seems like a false positive and/or couldn't figure how to fix it, so silence:
```
example/ssh2.c:227:38: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size 0 [-Werror=format-truncation=]
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                      ^~
example/ssh2.c:227:34: note: assuming directive output of 1 byte
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                  ^~~~~~~
example/ssh2.c:227:13: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 2
  227 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example/ssh2.c:228:38: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size 0 [-Werror=format-truncation=]
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                      ^~
example/ssh2.c:228:34: note: assuming directive output of 1 byte
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                  ^~~~~~~
example/ssh2.c:228:13: note: 'snprintf' output 3 or more bytes (assuming 4) into a destination of size 2
  228 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/7055480458/job/19205970397#step:10:98

Fix:
```
tests/openssh_fixture.c:116:38: error: ' 2>&1' directive output may be truncated writing 5 bytes into a region of size between 1 and 1024 [-Werror=format-truncation=]
tests/openssh_fixture.c:116:11: note: 'snprintf' output between 6 and 1029 bytes into a destination of size 1024
```
Ref: https://github.com/libssh2/libssh2/actions/runs/7055480458/job/19205969221#step:10:51

Tested via #1257
2023-12-01 13:31:47 +00:00
Viktor Szakats
2e57dcb9d2 example: fix indentation follow-up
Fix long line and fix more indentations.

Follow-up to 9e896e1b80
2023-12-01 13:02:11 +00:00
Viktor Szakats
9e896e1b80 example: fix indentation
Tested via #1257
2023-12-01 12:18:01 +00:00
Viktor Szakats
6c53815aa7 autotools: fix missed -pedantic and -Wall options for gcc
Follow-up to 5996fefe2b #1223

Tested via #1257
2023-12-01 05:50:12 +00:00
Viktor Szakats
c912408809 ci: show compiler in cross/cygwin job names
Tested via #1257
2023-12-01 05:50:12 +00:00
Viktor Szakats
4be5e33ae1 mbedtls: further improve disabling -Wredundant-decls
Move warning option suppression to `src/mbedtls.h` to surround the actual
external header #includes that need it.

Follow-up to ecec68a2c1 #1226
Follow-up to 7ecc309cd1 #1224

Tested via #1257
2023-12-01 05:49:25 +00:00
ren mingshuai
8d69e63db9 example: replace remaining libssh2_scp_recv with libssh2_scp_recv2 in output messages (#1258)
libssh2_scp_recv is deprecated and has been replaced by libssh2_scp_recv2
in prior commit.

Follow-up to 6c84a426be
2023-12-01 04:52:12 +01:00
Viktor Szakats
363dcbf449 openssl: use OpenSSL 3 HMAC API, add no-deprecated CI job
- use OpenSSL 3 API when available for HMAC.
  This fixes building with OpenSSL 3 `no-deprecated` builds.

- ensure we support pure OpenSSL 3 API by adding a CI job using
  OpenSSL 3 custom-built with `no-deprecated`.

Follow-up to b0ab005fe7 #1207

Fixes #1235
Closes #1243
2023-11-27 09:41:05 +00:00
Viktor Szakats
66108f02f0 ci: restore lost comment for FreeBSD [ci skip]
Follow-up to eee4e8055a
2023-11-26 12:00:23 +00:00
Viktor Szakats
0c9a8e3590 ci: add OpenBSD (v7.4) job + fix build error in example
- Use CMake, LibreSSL and clang from the base install.

- This uncovered a build error in `example/subsystem_netconf.c`, caused
  by using the `%n` printf mask. This is a security risk and some
  systems (notably OpenBSD) disable this feature.

  Fix it by applying this patch from OpenBSD ports (from 2021-09-11):
  https://cvsweb.openbsd.org/ports/security/libssh2/patches/patch-example_subsystem_netconf_c?rev=1.1&content-type=text/x-cvsweb-markup
  2c5b2f3e94
  "The old code is also broken, as it passes a pointer to a variable
  of a different size (on LP64).  There is no check for truncation,
  but buf[] is 1MB in size."
  Patch-by: naddy

  ```
  /home/runner/work/libssh2/libssh2/example/subsystem_netconf.c:252:17: error: '%n' format specifier support is deactivated and will call abort(3) [-Werror]
        "]]>]]>\n%n", (int *)&len);
                 ~^
  /home/runner/work/libssh2/libssh2/example/subsystem_netconf.c:270:17: error: '%n' format specifier support is deactivated and will call abort(3) [-Werror]
        "]]>]]>\n%n", (int *)&len);
                 ~^
  2 errors generated.
  ```
  Ref: https://github.com/libssh2/libssh2/actions/runs/6991449778/job/19022024280#step:3:420

Also made tests with arm64, but it takes consistently almost 14m to
finish the job, vs. 2-3m for the native amd64:
https://github.com/libssh2/libssh2/actions/runs/6991648984/job/19022440525
https://github.com/libssh2/libssh2/actions/runs/6991551220/job/19022233651

Cherry-picked from #1250
Closes #1250
2023-11-26 10:16:56 +00:00
Viktor Szakats
65c7a7a55a ci: add NetBSD (v9.3) job
Use CMake, OpenSSL (v1.1) and clang from the base install.

Cherry-picked from #1250
2023-11-26 10:16:01 +00:00
Viktor Szakats
eee4e8055a ci: update and speed up FreeBSD job
- switch to an alternate GitHub action. This one seems (more) actively
  maintained, and runs faster:
  https://github.com/cross-platform-actions/action

- use clang instead of gcc. clang is already present in the base
  install, saving install time and bandwidth.

- stop installing `openssl-quictls` and use the OpenSSL (v1.1) from
  the base system.
  (I'm suspecting that quictls before this patch wasn't detected by
  the build.)
  https://wiki.freebsd.org/OpenSSL

Cherry-picked from #1250
2023-11-26 10:16:01 +00:00
Viktor Szakats
c6589b8823 stop using leading underscores in macro names
Underscored macros are reserved for the compiler / standard lib / etc.
Stop using them in user code.

We used them as header guards in `src` and in `__FILESIZE` in `example`.

Closes #1248
2023-11-25 13:09:27 +00:00
Viktor Szakats
7494881617 ci: use absolute path in CMAKE_INSTALL_PREFIX
To make the installed locations unambiguous in the build logs.

Closes #1247
2023-11-25 11:25:52 +00:00
Viktor Szakats
efee91333b openssl: make a function static, add #ifdef comments
Follow-up to 0309229259 #248
where the function was added.

Also add comments to make `#ifdef` branches easier to follow in
`openssl.h`.

Closes #1246
2023-11-25 11:01:01 +00:00
Viktor Szakats
236e79a115 ci: boost mbedTLS build speed
Build times down to 4 seconds (from 18-20).

Closes #1245
2023-11-25 11:01:00 +00:00