Skip to content

src: silence compiler warnings 3 (change types) - #879

Closed
vszakats wants to merge 32 commits into
libssh2:masterfrom
vszakats:silence-warnings-1-3
Closed

vszakats wants to merge 32 commits into
libssh2:masterfrom
vszakats:silence-warnings-1-3

Conversation

@vszakats

@vszakats vszakats commented Mar 26, 2023 •

Copy link
Copy Markdown
Member

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 src: silence compiler warnings 1 #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 #846
Closes #879


TODO:

Partial list of warnings fixed:

src/kex.c:3110:..: warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
src/kex.c:3110:20: warning: conversion from 'size_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
src/kex.c:3110:20: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
src/kex.c:3110:20: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
src/kex.c:3110:20: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
src/kex.c:3128:33: warning: conversion from 'size_t' {aka 'long long unsigned int'} to 'uint32_t' {aka 'unsigned int'} may change value [-Wconversion]
src/kex.c:3128:33: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'uint32_t' {aka 'unsigned int'} may change value [-Wconversion]
src/kex.c:3205:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3205:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3206:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3207:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3207:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3208:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3209:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3209:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3210:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3211:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3211:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3212:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3213:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3213:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3214:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3215:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3215:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3216:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3217:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3217:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3218:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3219:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3219:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3220:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3221:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3221:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3222:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3223:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3223:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3224:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/libgcrypt.c:553:18: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
src/libgcrypt.c:569:22: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
src/libgcrypt.c:569:22: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
C:\projects\libssh2\src\wincng.c(2370): warning C4018: '>': signed/unsigned mismatch [C:\projects\libssh2\_builds\src\libssh2.vcxproj]
C:\projects\libssh2\src\wincng.c(2370): warning C4018: '>' : signed/unsigned mismatch [C:\projects\libssh2\_builds\src\libssh2.vcxproj]
./src/wincng.c:2369:34: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
        DWORD key_length_bytes = max(round_down(group_order, 8),
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/opt/mingw-w64/toolchain-x86_64/x86_64-w64-mingw32/include/minwindef.h:173:25: note: expanded from macro 'max'
                     ~  ^  ~
src/kex.c:3917:..: warning C4267: 'function': conversion from 'size_t' to 'unsigned int', possible loss of data
src/sftp.c:728:..: warning C4244: 'return': conversion from '__int64' to 'int', possible loss of data
src/sftp.c:889:..: warning C4244: '+=': conversion from 'ssize_t' to 'int', possible loss of data
src/openssl.h:188:54: warning: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Wconversion]
src/transport.c:873:50: warning: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Wconversion]
src/transport.c:873:50: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]

vszakats added 28 commits March 26, 2023 09:44
Explicitly truncate strings at uint32_t, instead of implicitly
truncate only their sizes sent through the wire.

```
src/kex.c:3110:..: warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
src/kex.c:3110:20: warning: conversion from 'size_t' {aka 'long long unsigned int'} to 'int' may change value [-Wconversion]
src/kex.c:3110:20: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
src/kex.c:3110:20: warning: implicit conversion loses integer precision: 'unsigned long long' to 'int' [-Wshorten-64-to-32]
src/kex.c:3110:20: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
src/kex.c:3128:33: warning: conversion from 'size_t' {aka 'long long unsigned int'} to 'uint32_t' {aka 'unsigned int'} may change value [-Wconversion]
src/kex.c:3128:33: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'uint32_t' {aka 'unsigned int'} may change value [-Wconversion]
src/kex.c:3205:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3205:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3206:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3207:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3207:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3208:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3209:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3209:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3210:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3211:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3211:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3212:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3213:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3213:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3214:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3215:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3215:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3216:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3217:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3217:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3218:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3219:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3219:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3220:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3221:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3221:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3222:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
src/kex.c:3223:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3223:37: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
src/kex.c:3224:..: warning C4267: 'function': conversion from 'size_t' to 'uint32_t', possible loss of data
```
```
src/libgcrypt.c:553:18: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
src/libgcrypt.c:569:22: warning: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
src/libgcrypt.c:569:22: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
```
Matching its public-facing wrapper and internal callers.
Instead of introducing `ssize_t nwritten` in blocks, it might be a
better solution to change `int rc` to `ssize_t`, though riskier.
Possibly `if(group_order <= 0)` might be better.

```
C:\projects\libssh2\src\wincng.c(2370): warning C4018: '>': signed/unsigned mismatch [C:\projects\libssh2\_builds\src\libssh2.vcxproj]
C:\projects\libssh2\src\wincng.c(2370): warning C4018: '>' : signed/unsigned mismatch [C:\projects\libssh2\_builds\src\libssh2.vcxproj]
```

```
./src/wincng.c:2369:34: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
        DWORD key_length_bytes = max(round_down(group_order, 8),
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/opt/mingw-w64/toolchain-x86_64/x86_64-w64-mingw32/include/minwindef.h:173:25: note: expanded from macro 'max'
                     ~  ^  ~
```
```
src/kex.c:3917:..: warning C4267: 'function': conversion from 'size_t' to 'unsigned int', possible loss of data
```
```
src/sftp.c:728:..: warning C4244: 'return': conversion from '__int64' to 'int', possible loss of data
```
```
src/sftp.c:889:..: warning C4244: '+=': conversion from 'ssize_t' to 'int', possible loss of data
```
Limit language string size to 256.
Also add length checks to openssl and wincng backends.

This might be necessary also for os400qc3.c.

```
src/openssl.h:188:54: warning: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Wconversion]
src/transport.c:873:50: warning: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Wconversion]
src/transport.c:873:50: warning: implicit conversion loses integer precision: 'ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
```
instead of unsigned int.

Also adjust some callers that used `int` to store its return value.
@vszakats
vszakats force-pushed the silence-warnings-1-3 branch from f3cd8f4 to 219b88c Compare March 26, 2023 09:45
@vszakats vszakats changed the title src: silence compiler warnings 3 src: silence compiler warnings 3 (type changes) Mar 26, 2023
@monnerat

Copy link
Copy Markdown
Contributor

libssh2_random() size type bumped int -> size_t. Checks added
for WinCNG and OpenSSL to return error if requested more than they
support (ULONG_MAX, INT_MAX respectively).

NOTE: os400qc3.c might potentially need a similar check added.

Thanks for the heads-up !
As you know, for 7 years, I'm not in a position anymore to assure OS400 products maintenance efficiently. That said, OS400 ILE C has a 32-bit size_t so it should not require a test for it.

There may be a possible problem related to changing the signedness of the argument. Maybe you should ask some curl OS400 people (i.e.: @jonrumsey?) if they are interested to test/contribute to libssh2 too. In addition, there has been some work done during this last 7 years that would need some OS400 additional support (SHA256, error return in _libssh2_random(), maybe others).

May I also suggest you adjust HACKING.CRYPTO according to you changes? Thanks.

@vszakats
vszakats force-pushed the silence-warnings-1-3 branch from 7f3ce1c to 1e9fdcb Compare March 26, 2023 16:43
@vszakats
vszakats force-pushed the silence-warnings-1-3 branch from 1e9fdcb to 7799dd6 Compare March 26, 2023 16:56
@vszakats vszakats changed the title src: silence compiler warnings 3 (type changes) src: silence compiler warnings 3 (change types) Mar 26, 2023
@vszakats

vszakats commented Mar 26, 2023 •

Copy link
Copy Markdown
Member Author

Thanks for your feedback @monnerat! I've updated HACKING-CRYPTO.

Found one place where a negative amount of random bytes might in theory be requested, in transport.c, _libssh2_transport_send(). This could have caused problems with all TLS backends except OpenSSL, even before this patch. Other callers are unsigned and/or positive constants.

Do you think we should add a check there? Are you aware of other places that may need attention?

diff --git a/src/transport.c b/src/transport.c
index e4ffc1a6..3de910a4 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -870,7 +870,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
     p->outbuf[4] = (unsigned char)padding_length;
 
     /* fill the padding area with random junk */
-    if(_libssh2_random(p->outbuf + 5 + data_len, padding_length)) {
+    if(padding_length > 0 &&
+       _libssh2_random(p->outbuf + 5 + data_len, padding_length)) {
         return _libssh2_error(session, LIBSSH2_ERROR_RANDGEN,
                               "Unable to get random bytes for packet padding");
     }

@monnerat

Copy link
Copy Markdown
Contributor

I've updated HACKING-CRYPTO

Super! I created this document a long time ago by reverse engineering and inference. It was not easy since most existing declarations were macros. This document helped me to implement the qc3 backend and can be very useful if someone wants to add another one (although not done every day!) providing it stays accurate. Thanks for this.

Other callers are unsigned and/or positive constants.

When I mentioned signedness change, I was not thinking of a -ve parameter value, but wondering about the possibility for the ILE C compiler to warn at compile time. I don't know how the Qc3GenPRNs function is effectively prototyped (doc says 4 binary bytes without more details)

Do you think we should add a check there? Are you aware of other places that may need attention?

No, but I have to say I haven't walked this source code for a long time !

@vszakats

Copy link
Copy Markdown
Member Author

Got it! No worries, and thanks for reminding me of the docs, I'd have missed it.

Tried to find OS400QC3 headers (or docs) over the internet earlier, but not a single hit (except in libssh2 itself ;). I'm going to merge this as-is, and someone with access to those can apply any necessary updates.

BTW, some internal interfaces are not enforced to a certain libssh2 type, just map as-is to TLS backends via macros. There are also inconsistencies in type and const usage. Possible things to take care of in the future.

@vszakats vszakats closed this in 5a96f49 Mar 26, 2023
@vszakats
vszakats deleted the silence-warnings-1-3 branch March 26, 2023 22:43
@monnerat

monnerat commented Mar 26, 2023 •

Copy link
Copy Markdown
Contributor

Tried to find OS400QC3 headers (or docs) over the internet earlier, but not a single hit (except in libssh2 itself ;). I'm going to merge this as-is, and someone with access to those can apply any necessary updates.

https://www.ibm.com/docs/en/i/7.5?topic=ssw_ibm_i_75/apis/qc3genprns.html
The effective C prototype should probably be found in the IBM-provided QSYSINC qc3cci.h header file but you must have access to an iSeries to see it :-(

I don't think many people outside of IBM have used any functions in the qc3 API ;-)

BTW, some internal interfaces are not enforced to a certain libssh2 type, just map as-is to TLS backends via macros. There are also inconsistencies in type and const usage. Possible things to take care of in the future.

Yes, that's what I noted when writing HACKING.CRYPTO. These macros are some kinds of "template" definitions (in the C++ style), but they introduce a fuzz level by lacking a little bit more strictness. An object language would have implemented this via a class interface.

@jonrumsey

Copy link
Copy Markdown

You can get a free account on an IBM i LPAR within a few minutes, for example https://www.pub400.com/

Anyway, looks like the prototype for Qc3GenPRNs in qc3prng.h uses an unsigned int for the length parameter and so the change to use a size_t is a good one;

#ifdef __ILEC400__                                                  
   #pragma argument (Qc3GenPRNs,OS,nowiden)                         
   void Qc3GenPRNs                                                  
                   (char *        , /* PRN data                   */
                    unsigned int  , /* PRN length                 */
                    char          , /* PRN type                   */
                    char          , /* PRN parity                 */
                    void *       ); /* Error Code                 */

@monnerat

Copy link
Copy Markdown
Contributor

You can get a free account on an IBM i LPAR within a few minutes,

Thanks for the hint Jon! I did it successfully, but unfortunately they have not installed the QADRT development files (I requested for it... wait and see). In all cases, this is a good mean to look at system header files.

Anyway, looks like the prototype for Qc3GenPRNs in qc3prng.h uses an unsigned int for the length parameter and so the change to use a size_t is a good one.

Thanks for confirmation.

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
lampmanyao pushed a commit to lampmanyao/libssh2 that referenced this pull request Jul 16, 2023
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
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jun 30, 2026
vszakats added a commit to vszakats/libssh2 that referenced this pull request Jun 30, 2026
As already done in WinCNG, but for negative only.

Follow-up to 5a96f49 libssh2#879

Closes libssh2#2154
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.

3 participants