Repository navigation
Conversation
Ref: libssh2#2402 Follow-up to fcf8307 libssh2#2239
There was a problem hiding this comment.
Pull request overview
This PR tightens the internal DH validation helper API by making ssh2_dh_validate() treat its inputs as read-only across the OpenSSL, mbedTLS, and libgcrypt backends, aligning intent with usage and reducing accidental mutation risk.
Changes:
- Update
ssh2_dh_validate()definitions in OpenSSL, mbedTLS, and libgcrypt backends to takeconst ssh2_bn *arguments. - Update the shared prototype in
src/crypto.haccordingly (unit-test helper).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/openssl.c | Const-qualify ssh2_dh_validate() parameters in the OpenSSL/WolfSSL backend implementation. |
| src/mbedtls.c | Const-qualify ssh2_dh_validate() parameters in the mbedTLS backend implementation. |
| src/libgcrypt.c | Const-qualify ssh2_dh_validate() parameters in the libgcrypt backend implementation. |
| src/crypto.h | Const-qualify the ssh2_dh_validate() prototype used by unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
To fix:
```
/home/runner/work/libssh2/libssh2/src/libgcrypt.c:704:24: error: passing 'const struct gcry_mpi *' to parameter of type 'gcry_mpi_t' (aka 'struct gcry_mpi *') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
704 | if(gcry_mpi_cmp_ui(f, 1) <= 0)
| ^
/usr/include/gcrypt.h:614:39: note: passing argument to parameter 'u' here
614 | int gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v);
| ^
In file included from /home/runner/work/libssh2/libssh2/bld/src/CMakeFiles/libssh2_static.dir/Unity/unity_0_c.c:40:
/home/runner/work/libssh2/libssh2/src/libgcrypt.c:710:26: error: passing 'const struct gcry_mpi *' to parameter of type 'gcry_mpi_t' (aka 'struct gcry_mpi *') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
710 | gcry_mpi_sub_ui(tmp, p, 1);
| ^
/usr/include/gcrypt.h:662:48: note: passing argument to parameter 'u' here
662 | void gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v );
| ^
In file included from /home/runner/work/libssh2/libssh2/bld/src/CMakeFiles/libssh2_static.dir/Unity/unity_0_c.c:40:
/home/runner/work/libssh2/libssh2/src/libgcrypt.c:711:21: error: passing 'const struct gcry_mpi *' to parameter of type 'gcry_mpi_t' (aka 'struct gcry_mpi *') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
711 | if(gcry_mpi_cmp(f, tmp) >= 0) {
| ^
/usr/include/gcrypt.h:609:36: note: passing argument to parameter 'u' here
609 | int gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v);
| ^
In file included from /home/runner/work/libssh2/libssh2/bld/src/CMakeFiles/libssh2_static.dir/Unity/unity_0_c.c:40:
/home/runner/work/libssh2/libssh2/src/libgcrypt.c:717:39: error: passing 'const struct gcry_mpi *' to parameter of type 'gcry_mpi_t' (aka 'struct gcry_mpi *') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
717 | for(i = 0, n = gcry_mpi_get_nbits(f), bits_set = 0; i < n; ++i)
| ^
/usr/include/gcrypt.h:775:45: note: passing argument to parameter 'a' here
775 | unsigned int gcry_mpi_get_nbits (gcry_mpi_t a);
| ^
In file included from /home/runner/work/libssh2/libssh2/bld/src/CMakeFiles/libssh2_static.dir/Unity/unity_0_c.c:40:
/home/runner/work/libssh2/libssh2/src/libgcrypt.c:718:30: error: passing 'const struct gcry_mpi *' to parameter of type 'gcry_mpi_t' (aka 'struct gcry_mpi *') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
718 | if(gcry_mpi_test_bit(f, i))
| ^
/usr/include/gcrypt.h:778:40: note: passing argument to parameter 'a' here
778 | int gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n);
| ^
5 errors generated.
```
Ref: https://github.com/libssh2/libssh2/actions/runs/30263895105/job/89969933303?pr=2436
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/libgcrypt.c:718
gcry_mpi_get_nbits()andgcry_mpi_test_bit()take a non-constgcry_mpi_t; after changingssh2_dh_validate()to acceptconst ssh2_bn*, the argument needs the same un-const cast used elsewhere to avoid const-discard warnings (often fatal under -Werror).
for(i = 0, n = gcry_mpi_get_nbits(SSH2_UNCONST(f)), bits_set = 0; i < n;
++i)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref: #2402
Follow-up to fcf8307 #2239