Skip to content

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Mar 14, 2023

Bring down C compiler warnings (as seen in CI and local builds) from around 400 to zero.

To reach this: add casts, adjust (mostly extending) types, add missing declarations, stop reusing variables, add a few size checks, add FIXMEs where type extension to a public API would be useful, adjusted platform guards and printfs masks, simplify _libssh2_ntohu64(), rework WinCNG Win32 interfaces with alignment warnings.

Also:

  • set ENABLE_WERROR in CMake CI builds.

Pending:

@vszakats vszakats marked this pull request as draft March 14, 2023 00:17
@vszakats vszakats force-pushed the compiler-warnings-1 branch 3 times, most recently from b22eef3 to 2dd5beb Compare March 14, 2023 20:36
vszakats added a commit that referenced this pull request Mar 14, 2023
- avoid outputting 4000 log lines by hiding the progress bar.
  Reduces log size by 5x.

- decrease timeout (from the default 2700 seconds).

- omit unnecessary output.

Tested as part of #846
@vszakats vszakats force-pushed the compiler-warnings-1 branch 5 times, most recently from e392d1f to 1558632 Compare March 16, 2023 04:21
@vszakats vszakats marked this pull request as ready for review March 16, 2023 04:35
@vszakats vszakats force-pushed the compiler-warnings-1 branch from 1558632 to bcecb59 Compare March 16, 2023 11:21
@vszakats vszakats force-pushed the compiler-warnings-1 branch from bcecb59 to ee53c81 Compare March 16, 2023 11:45
@vszakats
Copy link
Member Author

AppVeyor config updates merged via #849.

@vszakats vszakats force-pushed the compiler-warnings-1 branch from 2cd1ab0 to 792a7f0 Compare March 16, 2023 13:55
@vszakats
Copy link
Member Author

vszakats commented Mar 16, 2023

The number of warnings appearing in AppVeyor CI runs went down from (after dedupe) 371 to 0.

There are also warnings in ZLIB-specific code, not covered by AppVeyor CI. I didn't touch those.

@vszakats vszakats force-pushed the compiler-warnings-1 branch from cd2f6cf to c482832 Compare March 16, 2023 22:27
@vszakats
Copy link
Member Author

vszakats commented Mar 16, 2023

As for GitHub CI warnings, the before value was 794 (clang + gcc), now standing at 67. Of which 26 are in src and 2 in tests.

UPDATE: 0.

@vszakats vszakats force-pushed the compiler-warnings-1 branch 2 times, most recently from 9d0b943 to 602908d Compare March 17, 2023 11:32
@vszakats

This comment was marked as resolved.

@vszakats vszakats force-pushed the compiler-warnings-1 branch 2 times, most recently from 5649f31 to 78f3403 Compare March 17, 2023 13:31
@vszakats vszakats changed the title Address compiler warnings address compiler warnings Mar 17, 2023
@vszakats

This comment was marked as resolved.

@vszakats vszakats force-pushed the compiler-warnings-1 branch 3 times, most recently from 079bb32 to df82079 Compare March 17, 2023 16:48
@vszakats

This comment was marked as resolved.

@vszakats
Copy link
Member Author

Merged via #876, #877, #878, #879, #880.

@vszakats vszakats closed this Mar 26, 2023
@vszakats vszakats deleted the compiler-warnings-1 branch March 27, 2023 14:32
vszakats added a commit that referenced this pull request May 3, 2023
Twice. This tests are flaky and we haven't figured out why. In the
meantime use this workaround to test and log these issues, but also
ensure that CI run aren't flagged red because of it.

Also:
- kex: add debug message when hostkey `sig_verify` fails,
  to help tracking WinCNG KEX failures.
- test_ssh2: also add retry logic.
  I'm not quite sure this is correct. Please let me know.
- session_fixture: bump up `src_path` slots to fit retries and show
  message when hitting the limit.
- session_fixture: clear `kbd_password` static variable after use.
- session_fixture: close and deinit socket after use.
- session_fixture: deinit libssh2 after use.

Ref: #804 #846 #979 #1012 #1015

Cherry-picked from #1017
Closes #1023
vszakats added a commit to vszakats/libssh2 that referenced this pull request May 30, 2023
vszakats added a commit to vszakats/libssh2 that referenced this pull request May 30, 2023
vszakats added a commit that referenced this pull request May 30, 2023
vszakats added a commit that referenced this pull request Jun 13, 2023
Before 02f2700 #846 #876, we used
`%I64d'. That patch changed this to `%lld`. This patch uses `PRId64`
(defined in `inttypes.h`).

Fixes #1090
Closes #1091
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jun 25, 2023
Regression from b13936b libssh2#861 libssh2#846.
Update a variable name missed in above.

Reported-by: PewPewPew
Fixes libssh2#1105
Closes libssh2#1106
vszakats added a commit that referenced this pull request Jun 25, 2023
Regression from b13936b #861 #846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes #1105
Closes #1106
lampmanyao pushed a commit to lampmanyao/libssh2 that referenced this pull request Jul 16, 2023
lampmanyao pushed a commit to lampmanyao/libssh2 that referenced this pull request Jul 16, 2023
Before 02f2700 libssh2#846 libssh2#876, we used
`%I64d'. That patch changed this to `%lld`. This patch uses `PRId64`
(defined in `inttypes.h`).

Fixes libssh2#1090
Closes libssh2#1091
lampmanyao pushed a commit to lampmanyao/libssh2 that referenced this pull request Jul 16, 2023
Regression from b13936b libssh2#861 libssh2#846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes libssh2#1105
Closes libssh2#1106
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
- avoid outputting 4000 log lines by hiding the progress bar.
  Reduces log size by 5x.

- decrease timeout (from the default 2700 seconds).

- omit unnecessary output.

Tested as part of libssh2#846
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Patch-by: iruis on github
Assisted-by: Marc Hörsken
Bug libssh2#846, commit e348709.
Fixes libssh2#856
Closes libssh2#858
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Fix or silence all C compiler warnings discovered with (or without)
`PICKY_COMPILER=ON` (in CMake). This means all warnings showing up in
CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and
Windows cross-builds using gcc (12) and llvm/clang (14/15).

Also fix the expression `nread -= nread` in `sftp_RW_nonblock.c`.

Cherry-picked from: libssh2#846
Closes libssh2#861
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Avoid triggering warnings in macros coming from public libssh2 headers.

Cherry-picked from: libssh2#846
Closes libssh2#862
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Most of the changes aim to silence warnings by adding casts.

An assortment of other issues, mainly compiler warnings, resolved:

- unreachable code fixed by using `goto` in
  `publickey_response_success()` in `publickey.c`.

- potentially uninitialized variable in `sftp_open()`.

- MSVS-specific bogus warnings with `nid_type` in `kex.c`.

- check result of `kex_session_ecdh_curve_type()`.

- add missing function declarations.

- type changes to fit values without casts:
  - `cmd_len` in `scp_recv()` and `scp_send()`: `int` -> `size_t`
  - `Blowfish_expandstate()`, `Blowfish_expand0state()` loop counters:
    `uint16_t` -> `int`
  - `RECV_SEND_ALL()`: `int` -> `ssize_t`
  - `shell_quotearg()` -> `unsigned` -> `size_t`
  - `sig_len` in `_libssh2_mbedtls_rsa_sha2_sign()`:
    `unsigned` -> `size_t`
  - `prefs_len` in `libssh2_session_method_pref()`: `int` -> `size_t`
  - `firstsec` in `_libssh2_debug_low()`: `int` -> `long`
  - `method_len` in `libssh2_session_method_pref()`: `int` -> `size_t`

- simplify `_libssh2_ntohu64()`.

- fix `LIBSSH2_INT64_T_FORMAT` for MinGW.

- fix gcc warning by not using a bit field for
  `burn_optimistic_kexinit`.

- fix unused variable warning in `_libssh2_cipher_crypt()` in
  `libgcrypt.c`.

- fix unused variables with `HAVE_DISABLED_NONBLOCKING`.

- avoid const stripping with `BIO_new_mem_buf()` and OpenSSL 1.0.2 and
  newer.

- add a missing const in `wincng.h`.

- FIXME added for public:
  - `libssh2_channel_window_read_ex()` `read_avail` argument type.
  - `libssh2_base64_decode()` `datalen` argument type.

- fix possible overflow in `sftp_read()`.

  Ref: 4552c73

- formatting in `wincng.h`.

See warning details in the PR's individual commits.

Cherry-picked from libssh2#846
Closes libssh2#876
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Silence warnings in the ZLIB interface by adding casts and changing
types.

See PR for individual commits.

Cherry-picked from libssh2#846
Closes libssh2#878
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Apply type changes to avoid casts and warnings. In most cases this
means changing to a larger type, usually `size_t` or `ssize_t`.

Change signedness in a few places.

Also introduce new variables to avoid reusing them for multiple
purposes, to avoid casts and warnings.

- add FIXME for public `libssh2_sftp_readdir_ex()` return type.

- fix `_libssh2_mbedtls_rsa_sha2_verify()` to verify if `sig_len`
  is large enough.

- fix `_libssh2_dh_key_pair()` in `wincng.c` to return error if
  `group_order` input is negative.

  Maybe we should also reject zero?

- bump `_libssh2_random()` size type `int` -> `size_t`. Add checks
  for WinCNG and OpenSSL to return error if requested more than they
  support (`ULONG_MAX`, `INT_MAX` respectively).

- change `_libssh2_ntohu32()` return value `unsigned int` -> `uint32_t`.

- fix `_libssh2_mbedtls_bignum_random()` to check for a negative `top`
  input.

- size down `_libssh2_wincng_key_sha_verify()` `hashlen` to match
  Windows'.

- fix `session_disconnect()` to limit length of `lang_len`
  (to 256 bytes).

- fix bad syntax in an `assert()`.

- add a few `const` to casts.

- `while(1)` -> `for(;;)`.

- add casts that didn't fit into libssh2#876.

- update `docs/HACKING-CRYPTO` with new sizes.

May need review for OS400QC3: /cc @monnerat @jonrumsey

See warning details in the PR's individual commits.

Cherry-picked from libssh2#846
Closes libssh2#879
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Silence alignment warnings in WinCNG, by reworking the code.

Also add two unrelated casts to avoid gcc compiler warnings
in surrounding code.

`increases required alignment from 1 to 4 [-Wcast-align]`
`increases required alignment from 1 to 8 [-Wcast-align]`

See warning details in the PR's individual commits.

Reviewed-by: Marc Hörsken in <libssh2#846 (review)>
Cherry-picked from libssh2#846
Closes libssh2#880
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Twice. This tests are flaky and we haven't figured out why. In the
meantime use this workaround to test and log these issues, but also
ensure that CI run aren't flagged red because of it.

Also:
- kex: add debug message when hostkey `sig_verify` fails,
  to help tracking WinCNG KEX failures.
- test_ssh2: also add retry logic.
  I'm not quite sure this is correct. Please let me know.
- session_fixture: bump up `src_path` slots to fit retries and show
  message when hitting the limit.
- session_fixture: clear `kbd_password` static variable after use.
- session_fixture: close and deinit socket after use.
- session_fixture: deinit libssh2 after use.

Ref: libssh2#804 libssh2#846 libssh2#979 libssh2#1012 libssh2#1015

Cherry-picked from libssh2#1017
Closes libssh2#1023
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Before 02f2700 libssh2#846 libssh2#876, we used
`%I64d'. That patch changed this to `%lld`. This patch uses `PRId64`
(defined in `inttypes.h`).

Fixes libssh2#1090
Closes libssh2#1091
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
Regression from b13936b libssh2#861 libssh2#846.
Update a variable name missed above.

Reported-by: PewPewPew
Fixes libssh2#1105
Closes libssh2#1106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants