Repository navigation
Conversation
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.
f3cd8f4 to
219b88c
Compare
Thanks for the heads-up ! 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. |
7f3ce1c to
1e9fdcb
Compare
1e9fdcb to
7799dd6
Compare
|
Thanks for your feedback @monnerat! I've updated Found one place where a negative amount of random bytes might in theory be requested, in 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");
} |
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.
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
No, but I have to say I haven't walked this source code for a long time ! |
|
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. |
https://www.ibm.com/docs/en/i/7.5?topic=ssw_ibm_i_75/apis/qc3genprns.html I don't think many people outside of IBM have used any functions in the qc3 API ;-)
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. |
|
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 |
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.
Thanks for confirmation. |
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
As already done in WinCNG. Follow-up to 5a96f49 libssh2#879
As already done in WinCNG, but for negative only. Follow-up to 5a96f49 libssh2#879 Closes libssh2#2154
Apply type changes to avoid casts and warnings. In most cases this
means changing to a larger type, usually
size_torssize_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 ifsig_lenis large enough.
fix
_libssh2_dh_key_pair()inwincng.cto return error ifgroup_orderinput is negative.Maybe we should also reject zero?
bump
_libssh2_random()size typeint->size_t. Add checksfor WinCNG and OpenSSL to return error if requested more than they
support (
ULONG_MAX,INT_MAXrespectively).change
_libssh2_ntohu32()return valueunsigned int->uint32_t.fix
_libssh2_mbedtls_bignum_random()to check for a negativetopinput.
size down
_libssh2_wincng_key_sha_verify()hashlento matchWindows'.
fix
session_disconnect()to limit length oflang_len(to 256 bytes).
fix bad syntax in an
assert().add a few
constto casts.while(1)->for(;;).add casts that didn't fit into src: silence compiler warnings 1 #876.
update
docs/HACKING-CRYPTOwith 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: