1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-21 14:00:51 +03:00

src: silence compiler warnings 1

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: 4552c73cd5

- formatting in `wincng.h`.

See warning details in the PR's individual commits.

Cherry-picked from #846
Closes #876
This commit is contained in:
Viktor Szakats
2023-03-26 09:27:32 +00:00
parent bd078e12bd
commit 02f2700a61
25 changed files with 380 additions and 282 deletions

View File

@@ -131,10 +131,10 @@ agent_connect_unix(LIBSSH2_AGENT *agent)
} }
#define RECV_SEND_ALL(func, socket, buffer, length, flags, abstract) \ #define RECV_SEND_ALL(func, socket, buffer, length, flags, abstract) \
int rc; \
size_t finished = 0; \ size_t finished = 0; \
\ \
while(finished < length) { \ while(finished < length) { \
ssize_t rc; \
rc = func(socket, \ rc = func(socket, \
(char *)buffer + finished, length - finished, \ (char *)buffer + finished, length - finished, \
flags, abstract); \ flags, abstract); \
@@ -170,9 +170,10 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
/* Send the length of the request */ /* Send the length of the request */
if(transctx->state == agent_NB_state_request_created) { if(transctx->state == agent_NB_state_request_created) {
_libssh2_htonu32(buf, transctx->request_len); _libssh2_htonu32(buf, (uint32_t)transctx->request_len);
rc = _send_all(agent->session->send, agent->fd, rc = (int)_send_all(agent->session->send, agent->fd,
buf, sizeof buf, 0, &agent->session->abstract); buf, sizeof buf, 0,
&agent->session->abstract);
if(rc == -EAGAIN) if(rc == -EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
else if(rc < 0) else if(rc < 0)
@@ -183,8 +184,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
/* Send the request body */ /* Send the request body */
if(transctx->state == agent_NB_state_request_length_sent) { if(transctx->state == agent_NB_state_request_length_sent) {
rc = _send_all(agent->session->send, agent->fd, transctx->request, rc = (int)_send_all(agent->session->send, agent->fd,
transctx->request_len, 0, &agent->session->abstract); transctx->request, transctx->request_len, 0,
&agent->session->abstract);
if(rc == -EAGAIN) if(rc == -EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
else if(rc < 0) else if(rc < 0)
@@ -195,8 +197,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
/* Receive the length of a response */ /* Receive the length of a response */
if(transctx->state == agent_NB_state_request_sent) { if(transctx->state == agent_NB_state_request_sent) {
rc = _recv_all(agent->session->recv, agent->fd, rc = (int)_recv_all(agent->session->recv, agent->fd,
buf, sizeof buf, 0, &agent->session->abstract); buf, sizeof buf, 0,
&agent->session->abstract);
if(rc < 0) { if(rc < 0) {
if(rc == -EAGAIN) if(rc == -EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
@@ -214,8 +217,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
/* Receive the response body */ /* Receive the response body */
if(transctx->state == agent_NB_state_response_length_received) { if(transctx->state == agent_NB_state_response_length_received) {
rc = _recv_all(agent->session->recv, agent->fd, transctx->response, rc = (int)_recv_all(agent->session->recv, agent->fd,
transctx->response_len, 0, &agent->session->abstract); transctx->response, transctx->response_len, 0,
&agent->session->abstract);
if(rc < 0) { if(rc < 0) {
if(rc == -EAGAIN) if(rc == -EAGAIN)
return LIBSSH2_ERROR_EAGAIN; return LIBSSH2_ERROR_EAGAIN;
@@ -311,7 +315,7 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
transctx->request_len); transctx->request_len);
cds.dwData = PAGEANT_COPYDATA_ID; cds.dwData = PAGEANT_COPYDATA_ID;
cds.cbData = 1 + strlen(mapname); cds.cbData = (DWORD)(1 + strlen(mapname));
cds.lpData = mapname; cds.lpData = mapname;
id = SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds); id = SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds);

View File

@@ -88,7 +88,7 @@ bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
/* copy out */ /* copy out */
for(i = 0; i < BCRYPT_BLOCKS; i++) { for(i = 0; i < BCRYPT_BLOCKS; i++) {
out[4 * i + 3] = (cdata[i] >> 24) & 0xff; out[4 * i + 3] = (uint8_t)((cdata[i] >> 24) & 0xff);
out[4 * i + 2] = (cdata[i] >> 16) & 0xff; out[4 * i + 2] = (cdata[i] >> 16) & 0xff;
out[4 * i + 1] = (cdata[i] >> 8) & 0xff; out[4 * i + 1] = (cdata[i] >> 8) & 0xff;
out[4 * i + 0] = cdata[i] & 0xff; out[4 * i + 0] = cdata[i] & 0xff;
@@ -136,7 +136,7 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt,
/* generate key, sizeof(out) at a time */ /* generate key, sizeof(out) at a time */
for(count = 1; keylen > 0; count++) { for(count = 1; keylen > 0; count++) {
countsalt[saltlen + 0] = (count >> 24) & 0xff; countsalt[saltlen + 0] = (uint8_t)((count >> 24) & 0xff);
countsalt[saltlen + 1] = (count >> 16) & 0xff; countsalt[saltlen + 1] = (count >> 16) & 0xff;
countsalt[saltlen + 2] = (count >> 8) & 0xff; countsalt[saltlen + 2] = (count >> 8) & 0xff;
countsalt[saltlen + 3] = count & 0xff; countsalt[saltlen + 3] = count & 0xff;

View File

@@ -422,9 +422,9 @@ Blowfish_stream2word(const uint8_t *data, uint16_t databytes,
void void
Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes) Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes)
{ {
uint16_t i; int i;
int k;
uint16_t j; uint16_t j;
uint16_t k;
uint32_t temp; uint32_t temp;
uint32_t datal; uint32_t datal;
uint32_t datar; uint32_t datar;
@@ -461,9 +461,9 @@ void
Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes, Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes,
const uint8_t *key, uint16_t keybytes) const uint8_t *key, uint16_t keybytes)
{ {
uint16_t i; int i;
int k;
uint16_t j; uint16_t j;
uint16_t k;
uint32_t temp; uint32_t temp;
uint32_t datal; uint32_t datal;
uint32_t datar; uint32_t datar;
@@ -546,11 +546,11 @@ blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len)
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
Blowfish_encipher(c, &l, &r); Blowfish_encipher(c, &l, &r);
data[0] = l >> 24 & 0xff; data[0] = (uint8_t)(l >> 24 & 0xff);
data[1] = l >> 16 & 0xff; data[1] = l >> 16 & 0xff;
data[2] = l >> 8 & 0xff; data[2] = l >> 8 & 0xff;
data[3] = l & 0xff; data[3] = l & 0xff;
data[4] = r >> 24 & 0xff; data[4] = (uint8_t)(r >> 24 & 0xff);
data[5] = r >> 16 & 0xff; data[5] = r >> 16 & 0xff;
data[6] = r >> 8 & 0xff; data[6] = r >> 8 & 0xff;
data[7] = r & 0xff; data[7] = r & 0xff;
@@ -568,11 +568,11 @@ blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len)
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
Blowfish_decipher(c, &l, &r); Blowfish_decipher(c, &l, &r);
data[0] = l >> 24 & 0xff; data[0] = (uint8_t)(l >> 24 & 0xff);
data[1] = l >> 16 & 0xff; data[1] = l >> 16 & 0xff;
data[2] = l >> 8 & 0xff; data[2] = l >> 8 & 0xff;
data[3] = l & 0xff; data[3] = l & 0xff;
data[4] = r >> 24 & 0xff; data[4] = (uint8_t)(r >> 24 & 0xff);
data[5] = r >> 16 & 0xff; data[5] = r >> 16 & 0xff;
data[6] = r >> 8 & 0xff; data[6] = r >> 8 & 0xff;
data[7] = r & 0xff; data[7] = r & 0xff;
@@ -592,11 +592,11 @@ blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len)
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
Blowfish_encipher(c, &l, &r); Blowfish_encipher(c, &l, &r);
data[0] = l >> 24 & 0xff; data[0] = (uint8_t)(l >> 24 & 0xff);
data[1] = l >> 16 & 0xff; data[1] = l >> 16 & 0xff;
data[2] = l >> 8 & 0xff; data[2] = l >> 8 & 0xff;
data[3] = l & 0xff; data[3] = l & 0xff;
data[4] = r >> 24 & 0xff; data[4] = (uint8_t)(r >> 24 & 0xff);
data[5] = r >> 16 & 0xff; data[5] = r >> 16 & 0xff;
data[6] = r >> 8 & 0xff; data[6] = r >> 8 & 0xff;
data[7] = r & 0xff; data[7] = r & 0xff;
@@ -618,11 +618,11 @@ blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len)
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
Blowfish_decipher(c, &l, &r); Blowfish_decipher(c, &l, &r);
data[0] = l >> 24 & 0xff; data[0] = (uint8_t)(l >> 24 & 0xff);
data[1] = l >> 16 & 0xff; data[1] = l >> 16 & 0xff;
data[2] = l >> 8 & 0xff; data[2] = l >> 8 & 0xff;
data[3] = l & 0xff; data[3] = l & 0xff;
data[4] = r >> 24 & 0xff; data[4] = (uint8_t)(r >> 24 & 0xff);
data[5] = r >> 16 & 0xff; data[5] = r >> 16 & 0xff;
data[6] = r >> 8 & 0xff; data[6] = r >> 8 & 0xff;
data[7] = r & 0xff; data[7] = r & 0xff;
@@ -634,11 +634,11 @@ blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len)
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
Blowfish_decipher(c, &l, &r); Blowfish_decipher(c, &l, &r);
data[0] = l >> 24 & 0xff; data[0] = (uint8_t)(l >> 24 & 0xff);
data[1] = l >> 16 & 0xff; data[1] = l >> 16 & 0xff;
data[2] = l >> 8 & 0xff; data[2] = l >> 8 & 0xff;
data[3] = l & 0xff; data[3] = l & 0xff;
data[4] = r >> 24 & 0xff; data[4] = (uint8_t)(r >> 24 & 0xff);
data[5] = r >> 16 & 0xff; data[5] = r >> 16 & 0xff;
data[6] = r >> 8 & 0xff; data[6] = r >> 8 & 0xff;
data[7] = r & 0xff; data[7] = r & 0xff;

View File

@@ -470,11 +470,12 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
host = "0.0.0.0"; host = "0.0.0.0";
if(session->fwdLstn_state == libssh2_NB_state_idle) { if(session->fwdLstn_state == libssh2_NB_state_idle) {
session->fwdLstn_host_len = strlen(host); session->fwdLstn_host_len = (uint32_t)strlen(host);
/* 14 = packet_type(1) + request_len(4) + want_replay(1) + host_len(4) /* 14 = packet_type(1) + request_len(4) + want_replay(1) + host_len(4)
+ port(4) */ + port(4) */
session->fwdLstn_packet_len = session->fwdLstn_packet_len =
session->fwdLstn_host_len + (sizeof("tcpip-forward") - 1) + 14; session->fwdLstn_host_len +
(uint32_t)(sizeof("tcpip-forward") - 1) + 14;
/* Zero the whole thing out */ /* Zero the whole thing out */
memset(&session->fwdLstn_packet_requirev_state, 0, memset(&session->fwdLstn_packet_requirev_state, 0,
@@ -1332,7 +1333,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
_libssh2_store_str(&s, auth_proto ? auth_proto : "MIT-MAGIC-COOKIE-1", _libssh2_store_str(&s, auth_proto ? auth_proto : "MIT-MAGIC-COOKIE-1",
proto_len); proto_len);
_libssh2_store_u32(&s, cookie_len); _libssh2_store_u32(&s, (uint32_t)cookie_len);
if(auth_cookie) { if(auth_cookie) {
memcpy(s, auth_cookie, cookie_len); memcpy(s, auth_cookie, cookie_len);
} }
@@ -1482,7 +1483,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
*(s++) = 0x01; *(s++) = 0x01;
if(message) if(message)
_libssh2_store_u32(&s, message_len); _libssh2_store_u32(&s, (uint32_t)message_len);
channel->process_state = libssh2_NB_state_created; channel->process_state = libssh2_NB_state_created;
} }
@@ -1658,12 +1659,12 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid)
} }
channel->read_avail -= channel->flush_flush_bytes; channel->read_avail -= channel->flush_flush_bytes;
channel->remote.window_size -= channel->flush_flush_bytes; channel->remote.window_size -= (uint32_t)channel->flush_flush_bytes;
if(channel->flush_refund_bytes) { if(channel->flush_refund_bytes) {
int rc = int rc =
_libssh2_channel_receive_window_adjust(channel, _libssh2_channel_receive_window_adjust(channel,
channel->flush_refund_bytes, (uint32_t)channel->flush_refund_bytes,
1, NULL); 1, NULL);
if(rc == LIBSSH2_ERROR_EAGAIN) if(rc == LIBSSH2_ERROR_EAGAIN)
return rc; return rc;
@@ -1671,7 +1672,7 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid)
channel->flush_state = libssh2_NB_state_idle; channel->flush_state = libssh2_NB_state_idle;
return channel->flush_flush_bytes; return (int)channel->flush_flush_bytes;
} }
/* /*
@@ -1871,7 +1872,8 @@ libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
return (unsigned long)LIBSSH2_ERROR_BAD_USE; return (unsigned long)LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_receive_window_adjust(channel, adj, _libssh2_channel_receive_window_adjust(channel,
(uint32_t)adj,
force, &window)); force, &window));
/* stupid - but this is how it was made to work before and this is just /* stupid - but this is how it was made to work before and this is just
@@ -1902,8 +1904,9 @@ libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
return LIBSSH2_ERROR_BAD_USE; return LIBSSH2_ERROR_BAD_USE;
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_receive_window_adjust(channel, adj, force, _libssh2_channel_receive_window_adjust(channel,
window)); (uint32_t)adj,
force, window));
return rc; return rc;
} }
@@ -2005,8 +2008,8 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
(channel->remote.window_size < (channel->remote.window_size <
channel->remote.window_size_initial / 4 * 3 + buflen) ) { channel->remote.window_size_initial / 4 * 3 + buflen) ) {
uint32_t adjustment = channel->remote.window_size_initial + buflen - uint32_t adjustment = (uint32_t)(channel->remote.window_size_initial +
channel->remote.window_size; buflen - channel->remote.window_size);
if(adjustment < LIBSSH2_CHANNEL_MINADJUST) if(adjustment < LIBSSH2_CHANNEL_MINADJUST)
adjustment = LIBSSH2_CHANNEL_MINADJUST; adjustment = LIBSSH2_CHANNEL_MINADJUST;
@@ -2134,7 +2137,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
} }
channel->read_avail -= bytes_read; channel->read_avail -= bytes_read;
channel->remote.window_size -= bytes_read; channel->remote.window_size -= (uint32_t)bytes_read;
return bytes_read; return bytes_read;
} }
@@ -2167,8 +2170,8 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf,
if(buflen > recv_window) { if(buflen > recv_window) {
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
_libssh2_channel_receive_window_adjust(channel, buflen, _libssh2_channel_receive_window_adjust(channel,
1, NULL)); (uint32_t)buflen, 1, NULL));
} }
BLOCK_ADJUST(rc, channel->session, BLOCK_ADJUST(rc, channel->session,
@@ -2335,7 +2338,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
} }
/* store the size here only, the buffer is passed in as-is to /* store the size here only, the buffer is passed in as-is to
_libssh2_transport_send() */ _libssh2_transport_send() */
_libssh2_store_u32(&s, channel->write_bufwrite); _libssh2_store_u32(&s, (uint32_t)channel->write_bufwrite);
channel->write_packet_len = s - channel->write_packet; channel->write_packet_len = s - channel->write_packet;
_libssh2_debug((session, LIBSSH2_TRACE_CONN, _libssh2_debug((session, LIBSSH2_TRACE_CONN,
@@ -2360,7 +2363,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
"Unable to send channel data"); "Unable to send channel data");
} }
/* Shrink local window size */ /* Shrink local window size */
channel->local.window_size -= channel->write_bufwrite; channel->local.window_size -= (uint32_t)channel->write_bufwrite;
wrote += channel->write_bufwrite; wrote += channel->write_bufwrite;
@@ -2835,7 +2838,7 @@ libssh2_channel_free(LIBSSH2_CHANNEL *channel)
*/ */
LIBSSH2_API unsigned long LIBSSH2_API unsigned long
libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
unsigned long *read_avail, /* FIXME: -> size_t */ unsigned long *read_avail,
unsigned long *window_size_initial) unsigned long *window_size_initial)
{ {
if(!channel) if(!channel)
@@ -2875,7 +2878,7 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
packet = next_packet; packet = next_packet;
} }
*read_avail = bytes_queued; *read_avail = (unsigned long)bytes_queued;
} }
return channel->remote.window_size; return channel->remote.window_size;

View File

@@ -113,8 +113,11 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
if(!_libssh2_eob(&buf)) if(!_libssh2_eob(&buf))
return -1; return -1;
if(_libssh2_rsa_new(&rsactx, e, e_len, n, n_len, NULL, 0, if(_libssh2_rsa_new(&rsactx,
NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0)) { e, (unsigned long)e_len,
n, (unsigned long)n_len,
NULL, 0, NULL, 0, NULL, 0,
NULL, 0, NULL, 0, NULL, 0)) {
return -1; return -1;
} }
@@ -525,8 +528,12 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
if(!_libssh2_eob(&buf)) if(!_libssh2_eob(&buf))
return -1; return -1;
if(_libssh2_dsa_new(&dsactx, p, p_len, q, q_len, if(_libssh2_dsa_new(&dsactx,
g, g_len, y, y_len, NULL, 0)) { p, (unsigned long)p_len,
q, (unsigned long)q_len,
g, (unsigned long)g_len,
y, (unsigned long)y_len,
NULL, 0)) {
return -1; return -1;
} }

View File

@@ -531,7 +531,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
if(session->local.banner) { if(session->local.banner) {
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
strlen((char *) session->local.banner) - 2); (uint32_t)(strlen((char *) session->local.banner) - 2));
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
@@ -550,7 +550,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
} }
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
strlen((char *) session->remote.banner)); (uint32_t)strlen((char *) session->remote.banner));
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
@@ -558,7 +558,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
strlen((char *) session->remote.banner)); strlen((char *) session->remote.banner));
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
session->local.kexinit_len); (uint32_t)session->local.kexinit_len);
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
@@ -566,7 +566,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
session->local.kexinit_len); session->local.kexinit_len);
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
session->remote.kexinit_len); (uint32_t)session->remote.kexinit_len);
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
@@ -1428,7 +1428,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
_libssh2_bn_from_bin(key_state->g, g_len, g); _libssh2_bn_from_bin(key_state->g, g_len, g);
ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p, ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p,
p_len, 1, (int)p_len, 1,
(void *)&exchange_hash_ctx, (void *)&exchange_hash_ctx,
SSH_MSG_KEX_DH_GEX_INIT, SSH_MSG_KEX_DH_GEX_INIT,
SSH_MSG_KEX_DH_GEX_REPLY, SSH_MSG_KEX_DH_GEX_REPLY,
@@ -1556,7 +1556,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
_libssh2_bn_from_bin(key_state->g, g_len, g); _libssh2_bn_from_bin(key_state->g, g_len, g);
ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p, ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p,
p_len, 256, (int)p_len, 256,
(void *)&exchange_hash_ctx, (void *)&exchange_hash_ctx,
SSH_MSG_KEX_DH_GEX_INIT, SSH_MSG_KEX_DH_GEX_INIT,
SSH_MSG_KEX_DH_GEX_REPLY, SSH_MSG_KEX_DH_GEX_REPLY,
@@ -1605,7 +1605,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
(void)libssh2_sha##digest_type##_init(&ctx); \ (void)libssh2_sha##digest_type##_init(&ctx); \
if(session->local.banner) { \ if(session->local.banner) { \
_libssh2_htonu32(exchange_state->h_sig_comp, \ _libssh2_htonu32(exchange_state->h_sig_comp, \
strlen((char *) session->local.banner) - 2); \ (uint32_t)(strlen((char *) session->local.banner) - 2)); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
exchange_state->h_sig_comp, 4); \ exchange_state->h_sig_comp, 4); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
@@ -1626,7 +1626,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
} \ } \
\ \
_libssh2_htonu32(exchange_state->h_sig_comp, \ _libssh2_htonu32(exchange_state->h_sig_comp, \
strlen((char *) session->remote.banner)); \ (uint32_t)strlen((char *) session->remote.banner)); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
exchange_state->h_sig_comp, 4); \ exchange_state->h_sig_comp, 4); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
@@ -1635,7 +1635,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
session->remote.banner)); \ session->remote.banner)); \
\ \
_libssh2_htonu32(exchange_state->h_sig_comp, \ _libssh2_htonu32(exchange_state->h_sig_comp, \
session->local.kexinit_len); \ (uint32_t)session->local.kexinit_len); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
exchange_state->h_sig_comp, 4); \ exchange_state->h_sig_comp, 4); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
@@ -1643,7 +1643,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
session->local.kexinit_len); \ session->local.kexinit_len); \
\ \
_libssh2_htonu32(exchange_state->h_sig_comp, \ _libssh2_htonu32(exchange_state->h_sig_comp, \
session->remote.kexinit_len); \ (uint32_t)session->remote.kexinit_len); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
exchange_state->h_sig_comp, 4); \ exchange_state->h_sig_comp, 4); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
@@ -1659,7 +1659,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
session->server_hostkey_len); \ session->server_hostkey_len); \
\ \
_libssh2_htonu32(exchange_state->h_sig_comp, \ _libssh2_htonu32(exchange_state->h_sig_comp, \
public_key_len); \ (uint32_t)public_key_len); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
exchange_state->h_sig_comp, 4); \ exchange_state->h_sig_comp, 4); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
@@ -1667,7 +1667,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
public_key_len); \ public_key_len); \
\ \
_libssh2_htonu32(exchange_state->h_sig_comp, \ _libssh2_htonu32(exchange_state->h_sig_comp, \
server_public_key_len); \ (uint32_t)server_public_key_len); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
exchange_state->h_sig_comp, 4); \ exchange_state->h_sig_comp, 4); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
@@ -1712,6 +1712,11 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type)
else if(strcmp(name, "ecdh-sha2-nistp521") == 0) else if(strcmp(name, "ecdh-sha2-nistp521") == 0)
type = LIBSSH2_EC_CURVE_NISTP521; type = LIBSSH2_EC_CURVE_NISTP521;
else { else {
/* silence:
warning C4701: potentially uninitialized local variable 'type' used */
#if defined(_MSC_VER)
type = (libssh2_curve_type)0;
#endif
ret = -1; ret = -1;
} }
@@ -1907,7 +1912,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
goto clean_exit; goto clean_exit;
} }
_libssh2_htonu32(exchange_state->k_value, _libssh2_htonu32(exchange_state->k_value,
exchange_state->k_value_len - 4); (uint32_t)(exchange_state->k_value_len - 4));
if(_libssh2_bn_bits(exchange_state->k) % 8) { if(_libssh2_bn_bits(exchange_state->k) % 8) {
_libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4); _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4);
} }
@@ -2003,7 +2008,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
} }
memcpy(session->session_id, exchange_state->h_sig_comp, memcpy(session->session_id, exchange_state->h_sig_comp,
digest_length); digest_length);
session->session_id_len = digest_length; session->session_id_len = (uint32_t)digest_length;
_libssh2_debug((session, LIBSSH2_TRACE_KEX, _libssh2_debug((session, LIBSSH2_TRACE_KEX,
"session_id calculated")); "session_id calculated"));
} }
@@ -2298,7 +2303,13 @@ kex_method_ecdh_key_exchange
if(key_state->state == libssh2_NB_state_sent2) { if(key_state->state == libssh2_NB_state_sent2) {
(void)kex_session_ecdh_curve_type(session->kex->name, &type); rc = kex_session_ecdh_curve_type(session->kex->name, &type);
if(rc != 0) {
ret = _libssh2_error(session, -1,
"Unknown KEX nistp curve type");
goto ecdh_clean_exit;
}
ret = ecdh_sha2_nistp(session, type, key_state->data, ret = ecdh_sha2_nistp(session, type, key_state->data,
key_state->data_len, key_state->data_len,
@@ -2541,7 +2552,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
goto clean_exit; goto clean_exit;
} }
_libssh2_htonu32(exchange_state->k_value, _libssh2_htonu32(exchange_state->k_value,
exchange_state->k_value_len - 4); (uint32_t)(exchange_state->k_value_len - 4));
if(_libssh2_bn_bits(exchange_state->k) % 8) { if(_libssh2_bn_bits(exchange_state->k) % 8) {
_libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4); _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4);
} }
@@ -2613,7 +2624,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
} }
memcpy(session->session_id, exchange_state->h_sig_comp, memcpy(session->session_id, exchange_state->h_sig_comp,
digest_length); digest_length);
session->session_id_len = digest_length; session->session_id_len = (uint32_t)digest_length;
_libssh2_debug((session, LIBSSH2_TRACE_KEX, _libssh2_debug((session, LIBSSH2_TRACE_KEX,
"session_id calculated")); "session_id calculated"));
} }
@@ -3956,7 +3967,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
const char *prefs) const char *prefs)
{ {
char **prefvar, *s, *newprefs; char **prefvar, *s, *newprefs;
int prefs_len = strlen(prefs); size_t prefs_len = strlen(prefs);
const LIBSSH2_COMMON_METHOD **mlist; const LIBSSH2_COMMON_METHOD **mlist;
switch(method_type) { switch(method_type) {
@@ -4031,7 +4042,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
while(s && *s && mlist) { while(s && *s && mlist) {
char *p = strchr(s, ','); char *p = strchr(s, ',');
int method_len = p ? (p - s) : (int) strlen(s); size_t method_len = (p ? (size_t)(p - s) : strlen(s));
if(!kex_get_method_by_name(s, method_len, mlist)) { if(!kex_get_method_by_name(s, method_len, mlist)) {
/* Strip out unsupported method */ /* Strip out unsupported method */

View File

@@ -170,14 +170,14 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
break; break;
case LIBSSH2_KNOWNHOST_TYPE_SHA1: case LIBSSH2_KNOWNHOST_TYPE_SHA1:
rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen, rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen,
host, hostlen); host, (unsigned int)hostlen);
if(rc) if(rc)
goto error; goto error;
entry->name = ptr; entry->name = ptr;
entry->name_len = ptrlen; entry->name_len = ptrlen;
rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen, rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen,
salt, strlen(salt)); salt, (unsigned int)strlen(salt));
if(rc) if(rc)
goto error; goto error;
entry->salt = ptr; entry->salt = ptr;

View File

@@ -595,9 +595,10 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
_libssh2_cipher_type(algo), _libssh2_cipher_type(algo),
int encrypt, unsigned char *block, size_t blklen) int encrypt, unsigned char *block, size_t blklen)
{ {
int cipher = _libssh2_gcry_cipher(algo);
int ret; int ret;
(void)algo;
if(encrypt) { if(encrypt) {
ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen); ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen);
} }

View File

@@ -227,6 +227,7 @@
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
_libssh2_dh_secret(dhctx, secret, f, p) _libssh2_dh_secret(dhctx, secret, f, p)
#define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx)
extern void _libssh2_init_aes_ctr(void);
extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx); extern void _libssh2_dh_init(_libssh2_dh_ctx *dhctx);
extern int _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, extern int _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public,
_libssh2_bn *g, _libssh2_bn *p, _libssh2_bn *g, _libssh2_bn *p,

View File

@@ -164,10 +164,11 @@ struct iovec {
#include "crypto.h" #include "crypto.h"
#ifdef HAVE_WINSOCK2_H #ifdef HAVE_WINSOCK2_H
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
/* Force parameter type. */
#define recv(s, b, l, f) recv((s), (b), (int)(l), (f))
#define send(s, b, l, f) send((s), (b), (int)(l), (f))
#endif #endif
#ifndef SIZE_MAX #ifndef SIZE_MAX
@@ -201,20 +202,23 @@ struct iovec {
#define LIBSSH2_FREE(session, ptr) \ #define LIBSSH2_FREE(session, ptr) \
session->free((ptr), &(session)->abstract) session->free((ptr), &(session)->abstract)
#define LIBSSH2_IGNORE(session, data, datalen) \ #define LIBSSH2_IGNORE(session, data, datalen) \
session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract) session->ssh_msg_ignore((session), (data), (int)(datalen), \
&(session)->abstract)
#define LIBSSH2_DEBUG(session, always_display, message, message_len, \ #define LIBSSH2_DEBUG(session, always_display, message, message_len, \
language, language_len) \ language, language_len) \
session->ssh_msg_debug((session), (always_display), (message), \ session->ssh_msg_debug((session), (always_display), \
(message_len), (language), (language_len), \ (message), (int)(message_len), \
(language), (int)(language_len), \
&(session)->abstract) &(session)->abstract)
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, \ #define LIBSSH2_DISCONNECT(session, reason, message, message_len, \
language, language_len) \ language, language_len) \
session->ssh_msg_disconnect((session), (reason), (message), \ session->ssh_msg_disconnect((session), (reason), \
(message_len), (language), (language_len), \ (message), (int)(message_len), \
(language), (int)(language_len), \
&(session)->abstract) &(session)->abstract)
#define LIBSSH2_MACERROR(session, data, datalen) \ #define LIBSSH2_MACERROR(session, data, datalen) \
session->macerror((session), (data), (datalen), &(session)->abstract) session->macerror((session), (data), (int)(datalen), &(session)->abstract)
#define LIBSSH2_X11_OPEN(channel, shost, sport) \ #define LIBSSH2_X11_OPEN(channel, shost, sport) \
channel->session->x11(((channel)->session), (channel), \ channel->session->x11(((channel)->session), (channel), \
(shost), (sport), (&(channel)->session->abstract)) (shost), (sport), (&(channel)->session->abstract))
@@ -633,7 +637,7 @@ struct _LIBSSH2_SESSION
/* Agreed Key Exchange Method */ /* Agreed Key Exchange Method */
const LIBSSH2_KEX_METHOD *kex; const LIBSSH2_KEX_METHOD *kex;
unsigned int burn_optimistic_kexinit:1; unsigned int burn_optimistic_kexinit;
unsigned char *session_id; unsigned char *session_id;
uint32_t session_id_len; uint32_t session_id_len;
@@ -1142,7 +1146,7 @@ void _libssh2_init_if_needed(void);
#define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0])) #define ARRAY_SIZE(a) (sizeof ((a)) / sizeof ((a)[0]))
/* define to output the libssh2_int64_t type in a *printf() */ /* define to output the libssh2_int64_t type in a *printf() */
#if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__) #if defined(__BORLANDC__) || defined(_MSC_VER)
#define LIBSSH2_INT64_T_FORMAT "I64d" #define LIBSSH2_INT64_T_FORMAT "I64d"
#else #else
#define LIBSSH2_INT64_T_FORMAT "lld" #define LIBSSH2_INT64_T_FORMAT "lld"

View File

@@ -126,7 +126,7 @@ _libssh2_mbedtls_cipher_init(_libssh2_cipher_ctx *ctx,
if(!ret) if(!ret)
ret = mbedtls_cipher_setkey(ctx, ret = mbedtls_cipher_setkey(ctx,
secret, secret,
mbedtls_cipher_info_get_key_bitlen(cipher_info), (int)mbedtls_cipher_info_get_key_bitlen(cipher_info),
op); op);
if(!ret) if(!ret)
@@ -526,11 +526,11 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
#if MBEDTLS_VERSION_NUMBER >= 0x03000000 #if MBEDTLS_VERSION_NUMBER >= 0x03000000
ret = mbedtls_rsa_pkcs1_verify(rsactx, ret = mbedtls_rsa_pkcs1_verify(rsactx,
md_type, hash_len, md_type, (unsigned int)hash_len,
hash, sig); hash, sig);
#else #else
ret = mbedtls_rsa_pkcs1_verify(rsactx, NULL, NULL, MBEDTLS_RSA_PUBLIC, ret = mbedtls_rsa_pkcs1_verify(rsactx, NULL, NULL, MBEDTLS_RSA_PUBLIC,
md_type, hash_len, md_type, (unsigned int)hash_len,
hash, sig); hash, sig);
#endif #endif
free(hash); free(hash);
@@ -558,7 +558,7 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session,
{ {
int ret; int ret;
unsigned char *sig; unsigned char *sig;
unsigned int sig_len; size_t sig_len;
int md_type; int md_type;
(void)hash_len; (void)hash_len;
@@ -587,11 +587,11 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session,
ret = mbedtls_rsa_pkcs1_sign(rsa, ret = mbedtls_rsa_pkcs1_sign(rsa,
mbedtls_ctr_drbg_random, mbedtls_ctr_drbg_random,
&_libssh2_mbedtls_ctr_drbg, &_libssh2_mbedtls_ctr_drbg,
md_type, hash_len, md_type, (unsigned int)hash_len,
hash, sig); hash, sig);
#else #else
ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE,
md_type, hash_len, md_type, (unsigned int)hash_len,
hash, sig); hash, sig);
#endif #endif
} }
@@ -634,8 +634,8 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session,
unsigned char *key; unsigned char *key;
unsigned char *p; unsigned char *p;
e_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E)); e_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E));
n_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N)); n_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N));
/* Key form is "ssh-rsa" + e + n. */ /* Key form is "ssh-rsa" + e + n. */
len = 4 + 7 + 4 + e_bytes + 4 + n_bytes; len = 4 + 7 + 4 + e_bytes + 4 + n_bytes;

View File

@@ -124,7 +124,7 @@
#define libssh2_hmac_cleanup(pctx) \ #define libssh2_hmac_cleanup(pctx) \
mbedtls_md_free(pctx) mbedtls_md_free(pctx)
#define libssh2_hmac_update(ctx, data, datalen) \ #define libssh2_hmac_update(ctx, data, datalen) \
mbedtls_md_hmac_update(&ctx, (unsigned char *) data, datalen) mbedtls_md_hmac_update(&ctx, (const unsigned char *) data, datalen)
#define libssh2_hmac_final(ctx, hash) \ #define libssh2_hmac_final(ctx, hash) \
mbedtls_md_hmac_finish(&ctx, hash) mbedtls_md_hmac_finish(&ctx, hash)
@@ -152,7 +152,7 @@
#define libssh2_sha1_init(pctx) \ #define libssh2_sha1_init(pctx) \
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0) _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0)
#define libssh2_sha1_update(ctx, data, datalen) \ #define libssh2_sha1_update(ctx, data, datalen) \
mbedtls_md_update(&ctx, (unsigned char *) data, datalen) mbedtls_md_update(&ctx, (const unsigned char *) data, datalen)
#define libssh2_sha1_final(ctx, hash) \ #define libssh2_sha1_final(ctx, hash) \
_libssh2_mbedtls_hash_final(&ctx, hash) _libssh2_mbedtls_hash_final(&ctx, hash)
#define libssh2_sha1(data, datalen, hash) \ #define libssh2_sha1(data, datalen, hash) \
@@ -168,7 +168,7 @@
#define libssh2_sha256_init(pctx) \ #define libssh2_sha256_init(pctx) \
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0) _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0)
#define libssh2_sha256_update(ctx, data, datalen) \ #define libssh2_sha256_update(ctx, data, datalen) \
mbedtls_md_update(&ctx, (unsigned char *) data, datalen) mbedtls_md_update(&ctx, (const unsigned char *) data, datalen)
#define libssh2_sha256_final(ctx, hash) \ #define libssh2_sha256_final(ctx, hash) \
_libssh2_mbedtls_hash_final(&ctx, hash) _libssh2_mbedtls_hash_final(&ctx, hash)
#define libssh2_sha256(data, datalen, hash) \ #define libssh2_sha256(data, datalen, hash) \
@@ -185,7 +185,7 @@
#define libssh2_sha384_init(pctx) \ #define libssh2_sha384_init(pctx) \
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0) _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0)
#define libssh2_sha384_update(ctx, data, datalen) \ #define libssh2_sha384_update(ctx, data, datalen) \
mbedtls_md_update(&ctx, (unsigned char *) data, datalen) mbedtls_md_update(&ctx, (const unsigned char *) data, datalen)
#define libssh2_sha384_final(ctx, hash) \ #define libssh2_sha384_final(ctx, hash) \
_libssh2_mbedtls_hash_final(&ctx, hash) _libssh2_mbedtls_hash_final(&ctx, hash)
#define libssh2_sha384(data, datalen, hash) \ #define libssh2_sha384(data, datalen, hash) \
@@ -202,7 +202,7 @@
#define libssh2_sha512_init(pctx) \ #define libssh2_sha512_init(pctx) \
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0) _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0)
#define libssh2_sha512_update(ctx, data, datalen) \ #define libssh2_sha512_update(ctx, data, datalen) \
mbedtls_md_update(&ctx, (unsigned char *) data, datalen) mbedtls_md_update(&ctx, (const unsigned char *) data, datalen)
#define libssh2_sha512_final(ctx, hash) \ #define libssh2_sha512_final(ctx, hash) \
_libssh2_mbedtls_hash_final(&ctx, hash) _libssh2_mbedtls_hash_final(&ctx, hash)
#define libssh2_sha512(data, datalen, hash) \ #define libssh2_sha512(data, datalen, hash) \
@@ -219,7 +219,7 @@
#define libssh2_md5_init(pctx) \ #define libssh2_md5_init(pctx) \
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0) _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0)
#define libssh2_md5_update(ctx, data, datalen) \ #define libssh2_md5_update(ctx, data, datalen) \
mbedtls_md_update(&ctx, (unsigned char *) data, datalen) mbedtls_md_update(&ctx, (const unsigned char *) data, datalen)
#define libssh2_md5_final(ctx, hash) \ #define libssh2_md5_final(ctx, hash) \
_libssh2_mbedtls_hash_final(&ctx, hash) _libssh2_mbedtls_hash_final(&ctx, hash)
#define libssh2_md5(data, datalen, hash) \ #define libssh2_md5(data, datalen, hash) \
@@ -595,6 +595,8 @@ void
_libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx); _libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx);
#endif /* LIBSSH2_ECDSA */ #endif /* LIBSSH2_ECDSA */
extern void
_libssh2_init_aes_ctr(void);
extern void extern void
_libssh2_dh_init(_libssh2_dh_ctx *dhctx); _libssh2_dh_init(_libssh2_dh_ctx *dhctx);
extern int extern int

View File

@@ -79,7 +79,7 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
va_start(args, fmt); va_start(args, fmt);
n = vsnprintf(cp, cp_max_len, fmt, args); n = vsnprintf(cp, cp_max_len, fmt, args);
va_end(args); va_end(args);
return (n < cp_max_len) ? n : (cp_max_len - 1); return (n < (int)cp_max_len) ? n : (int)(cp_max_len - 1);
} }
#endif #endif
@@ -230,14 +230,14 @@ _libssh2_ntohu32(const unsigned char *buf)
libssh2_uint64_t libssh2_uint64_t
_libssh2_ntohu64(const unsigned char *buf) _libssh2_ntohu64(const unsigned char *buf)
{ {
unsigned long msl, lsl; return ((libssh2_uint64_t)buf[0] << 56)
| ((libssh2_uint64_t)buf[1] << 48)
msl = ((libssh2_uint64_t)buf[0] << 24) | ((libssh2_uint64_t)buf[1] << 16) | ((libssh2_uint64_t)buf[2] << 40)
| ((libssh2_uint64_t)buf[2] << 8) | (libssh2_uint64_t)buf[3]; | ((libssh2_uint64_t)buf[3] << 32)
lsl = ((libssh2_uint64_t)buf[4] << 24) | ((libssh2_uint64_t)buf[5] << 16) | ((libssh2_uint64_t)buf[4] << 24)
| ((libssh2_uint64_t)buf[6] << 8) | (libssh2_uint64_t)buf[7]; | ((libssh2_uint64_t)buf[5] << 16)
| ((libssh2_uint64_t)buf[6] << 8)
return ((libssh2_uint64_t)msl <<32) | lsl; | ((libssh2_uint64_t)buf[7]);
} }
/* _libssh2_htonu32 /* _libssh2_htonu32
@@ -245,7 +245,7 @@ _libssh2_ntohu64(const unsigned char *buf)
void void
_libssh2_htonu32(unsigned char *buf, uint32_t value) _libssh2_htonu32(unsigned char *buf, uint32_t value)
{ {
buf[0] = (value >> 24) & 0xFF; buf[0] = (unsigned char)((value >> 24) & 0xFF);
buf[1] = (value >> 16) & 0xFF; buf[1] = (value >> 16) & 0xFF;
buf[2] = (value >> 8) & 0xFF; buf[2] = (value >> 8) & 0xFF;
buf[3] = value & 0xFF; buf[3] = value & 0xFF;
@@ -281,7 +281,7 @@ void _libssh2_store_bignum2_bytes(unsigned char **buf,
for(p = bytes; len > 0 && *p == 0; --len, ++p) {} for(p = bytes; len > 0 && *p == 0; --len, ++p) {}
extraByte = (len > 0 && (p[0] & 0x80) != 0); extraByte = (len > 0 && (p[0] & 0x80) != 0);
_libssh2_store_u32(buf, len + extraByte); _libssh2_store_u32(buf, (uint32_t)(len + extraByte));
if(extraByte) { if(extraByte) {
*buf[0] = 0; *buf[0] = 0;
@@ -319,6 +319,7 @@ static const short base64_reverse_table[256] = {
* *
* Decode a base64 chunk and store it into a newly alloc'd buffer * Decode a base64 chunk and store it into a newly alloc'd buffer
*/ */
/* FIXME: datalen, src_len -> size_t */
LIBSSH2_API int LIBSSH2_API int
libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
unsigned int *datalen, const char *src, unsigned int *datalen, const char *src,
@@ -344,15 +345,15 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
d[len] = (unsigned char)(v << 2); d[len] = (unsigned char)(v << 2);
break; break;
case 1: case 1:
d[len++] |= v >> 4; d[len++] |= (unsigned char)(v >> 4);
d[len] = (unsigned char)(v << 4); d[len] = (unsigned char)(v << 4);
break; break;
case 2: case 2:
d[len++] |= v >> 2; d[len++] |= (unsigned char)(v >> 2);
d[len] = (unsigned char)(v << 6); d[len] = (unsigned char)(v << 6);
break; break;
case 3: case 3:
d[len++] |= v; d[len++] |= (unsigned char)v;
break; break;
} }
i++; i++;
@@ -483,7 +484,7 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format,
int len, msglen, buflen = sizeof(buffer); int len, msglen, buflen = sizeof(buffer);
va_list vargs; va_list vargs;
struct timeval now; struct timeval now;
static int firstsec; static long firstsec;
static const char *const contexts[] = { static const char *const contexts[] = {
"Unknown", "Unknown",
"Transport", "Transport",

View File

@@ -119,29 +119,29 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
BIGNUM * iqmp = 0; BIGNUM * iqmp = 0;
e = BN_new(); e = BN_new();
BN_bin2bn(edata, elen, e); BN_bin2bn(edata, (int) elen, e);
n = BN_new(); n = BN_new();
BN_bin2bn(ndata, nlen, n); BN_bin2bn(ndata, (int) nlen, n);
if(ddata) { if(ddata) {
d = BN_new(); d = BN_new();
BN_bin2bn(ddata, dlen, d); BN_bin2bn(ddata, (int) dlen, d);
p = BN_new(); p = BN_new();
BN_bin2bn(pdata, plen, p); BN_bin2bn(pdata, (int) plen, p);
q = BN_new(); q = BN_new();
BN_bin2bn(qdata, qlen, q); BN_bin2bn(qdata, (int) qlen, q);
dmp1 = BN_new(); dmp1 = BN_new();
BN_bin2bn(e1data, e1len, dmp1); BN_bin2bn(e1data, (int) e1len, dmp1);
dmq1 = BN_new(); dmq1 = BN_new();
BN_bin2bn(e2data, e2len, dmq1); BN_bin2bn(e2data, (int) e2len, dmq1);
iqmp = BN_new(); iqmp = BN_new();
BN_bin2bn(coeffdata, coefflen, iqmp); BN_bin2bn(coeffdata, (int) coefflen, iqmp);
} }
*rsa = RSA_new(); *rsa = RSA_new();
@@ -196,16 +196,23 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
nid_type = NID_sha512; nid_type = NID_sha512;
ret = _libssh2_sha512(m, m_len, hash); ret = _libssh2_sha512(m, m_len, hash);
} }
else else {
/* silence:
warning C4701: potentially uninitialized local variable 'nid_type' used */
#if defined(_MSC_VER)
nid_type = 0;
#endif
ret = -1; /* unsupported digest */ ret = -1; /* unsupported digest */
}
if(ret != 0) { if(ret != 0) {
free(hash); free(hash);
return -1; /* failure */ return -1; /* failure */
} }
ret = RSA_verify(nid_type, hash, hash_len, ret = RSA_verify(nid_type, hash, (unsigned int) hash_len,
(unsigned char *) sig, sig_len, rsactx); (unsigned char *) sig,
(unsigned int) sig_len, rsactx);
free(hash); free(hash);
@@ -242,20 +249,20 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx,
BIGNUM * priv_key = NULL; BIGNUM * priv_key = NULL;
p_bn = BN_new(); p_bn = BN_new();
BN_bin2bn(p, p_len, p_bn); BN_bin2bn(p, (int) p_len, p_bn);
q_bn = BN_new(); q_bn = BN_new();
BN_bin2bn(q, q_len, q_bn); BN_bin2bn(q, (int) q_len, q_bn);
g_bn = BN_new(); g_bn = BN_new();
BN_bin2bn(g, g_len, g_bn); BN_bin2bn(g, (int) g_len, g_bn);
pub_key = BN_new(); pub_key = BN_new();
BN_bin2bn(y, y_len, pub_key); BN_bin2bn(y, (int) y_len, pub_key);
if(x_len) { if(x_len) {
priv_key = BN_new(); priv_key = BN_new();
BN_bin2bn(x, x_len, priv_key); BN_bin2bn(x, (int) x_len, priv_key);
} }
*dsactx = DSA_new(); *dsactx = DSA_new();
@@ -348,6 +355,11 @@ _libssh2_ecdsa_curve_type_from_name(const char *name,
else if(strcmp(name, "ecdsa-sha2-nistp521") == 0) else if(strcmp(name, "ecdsa-sha2-nistp521") == 0)
type = LIBSSH2_EC_CURVE_NISTP521; type = LIBSSH2_EC_CURVE_NISTP521;
else { else {
/* silence:
warning C4701: potentially uninitialized local variable 'type' used */
#if defined(_MSC_VER)
type = (libssh2_curve_type)0;
#endif
ret = -1; ret = -1;
} }
@@ -415,17 +427,17 @@ _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx,
BIGNUM *pr = BN_new(); BIGNUM *pr = BN_new();
BIGNUM *ps = BN_new(); BIGNUM *ps = BN_new();
BN_bin2bn(r, r_len, pr); BN_bin2bn(r, (int) r_len, pr);
BN_bin2bn(s, s_len, ps); BN_bin2bn(s, (int) s_len, ps);
ECDSA_SIG_set0(ecdsa_sig, pr, ps); ECDSA_SIG_set0(ecdsa_sig, pr, ps);
#else #else
ECDSA_SIG ecdsa_sig_; ECDSA_SIG ecdsa_sig_;
ECDSA_SIG *ecdsa_sig = &ecdsa_sig_; ECDSA_SIG *ecdsa_sig = &ecdsa_sig_;
ecdsa_sig_.r = BN_new(); ecdsa_sig_.r = BN_new();
BN_bin2bn(r, r_len, ecdsa_sig_.r); BN_bin2bn(r, (int) r_len, ecdsa_sig_.r);
ecdsa_sig_.s = BN_new(); ecdsa_sig_.s = BN_new();
BN_bin2bn(s, s_len, ecdsa_sig_.s); BN_bin2bn(s, (int) s_len, ecdsa_sig_.s);
#endif #endif
if(type == LIBSSH2_EC_CURVE_NISTP256) { if(type == LIBSSH2_EC_CURVE_NISTP256) {
@@ -477,9 +489,9 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
(void) encrypt; (void) encrypt;
#ifdef HAVE_OPAQUE_STRUCTS #ifdef HAVE_OPAQUE_STRUCTS
ret = EVP_Cipher(*ctx, buf, block, blocksize); ret = EVP_Cipher(*ctx, buf, block, (unsigned int) blocksize);
#else #else
ret = EVP_Cipher(ctx, buf, block, blocksize); ret = EVP_Cipher(ctx, buf, block, (unsigned int) blocksize);
#endif #endif
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || \ #if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || \
@@ -525,7 +537,7 @@ void _libssh2_openssl_crypto_exit(void)
static int static int
passphrase_cb(char *buf, int size, int rwflag, char *passphrase) passphrase_cb(char *buf, int size, int rwflag, char *passphrase)
{ {
int passphrase_len = strlen(passphrase); int passphrase_len = (int) strlen(passphrase);
(void) rwflag; (void) rwflag;
if(passphrase_len > (size - 1)) { if(passphrase_len > (size - 1)) {
@@ -551,7 +563,11 @@ read_private_key_from_memory(void **key_ctx,
*key_ctx = NULL; *key_ctx = NULL;
bp = BIO_new_mem_buf((char *)filedata, filedata_len); #if OPENSSL_VERSION_NUMBER >= 0x1000200fL
bp = BIO_new_mem_buf(filedata, (int)filedata_len);
#else
bp = BIO_new_mem_buf((char *)filedata, (int)filedata_len);
#endif
if(!bp) { if(!bp) {
return -1; return -1;
} }
@@ -840,9 +856,14 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session,
return -1; return -1;
} }
if((rc = _libssh2_rsa_new(&rsa, e, elen, n, nlen, d, dlen, p, plen, if((rc = _libssh2_rsa_new(&rsa,
q, qlen, NULL, 0, NULL, 0, e, (unsigned long)elen,
coeff, coefflen)) != 0) { n, (unsigned long)nlen,
d, (unsigned long)dlen,
p, (unsigned long)plen,
q, (unsigned long)qlen,
NULL, 0, NULL, 0,
coeff, (unsigned long)coefflen)) != 0) {
_libssh2_debug((session, _libssh2_debug((session,
LIBSSH2_TRACE_AUTH, LIBSSH2_TRACE_AUTH,
"Could not create RSA private key")); "Could not create RSA private key"));
@@ -1143,8 +1164,12 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session,
return -1; return -1;
} }
rc = _libssh2_dsa_new(&dsa, p, plen, q, qlen, g, glen, pub_key, pub_len, rc = _libssh2_dsa_new(&dsa,
priv_key, priv_len); p, (unsigned long)plen,
q, (unsigned long)qlen,
g, (unsigned long)glen,
pub_key, (unsigned long)pub_len,
priv_key, (unsigned long)priv_len);
if(rc != 0) { if(rc != 0) {
_libssh2_debug((session, _libssh2_debug((session,
LIBSSH2_ERROR_PROTO, LIBSSH2_ERROR_PROTO,
@@ -1432,7 +1457,7 @@ gen_publickey_from_ed_evp(LIBSSH2_SESSION *session,
} }
_libssh2_store_str(&bufPos, methodName, sizeof(methodName) - 1); _libssh2_store_str(&bufPos, methodName, sizeof(methodName) - 1);
_libssh2_store_u32(&bufPos, rawKeyLen); _libssh2_store_u32(&bufPos, (uint32_t) rawKeyLen);
if(EVP_PKEY_get_raw_public_key(pk, bufPos, &rawKeyLen) != 1) { if(EVP_PKEY_get_raw_public_key(pk, bufPos, &rawKeyLen) != 1) {
_libssh2_error(session, LIBSSH2_ERROR_PROTO, _libssh2_error(session, LIBSSH2_ERROR_PROTO,
@@ -2002,11 +2027,14 @@ _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session,
} }
if(hash_len == SHA_DIGEST_LENGTH) if(hash_len == SHA_DIGEST_LENGTH)
ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx); ret = RSA_sign(NID_sha1,
hash, (unsigned int) hash_len, sig, &sig_len, rsactx);
else if(hash_len == SHA256_DIGEST_LENGTH) else if(hash_len == SHA256_DIGEST_LENGTH)
ret = RSA_sign(NID_sha256, hash, hash_len, sig, &sig_len, rsactx); ret = RSA_sign(NID_sha256,
hash, (unsigned int) hash_len, sig, &sig_len, rsactx);
else if(hash_len == SHA512_DIGEST_LENGTH) else if(hash_len == SHA512_DIGEST_LENGTH)
ret = RSA_sign(NID_sha512, hash, hash_len, sig, &sig_len, rsactx); ret = RSA_sign(NID_sha512,
hash, (unsigned int) hash_len, sig, &sig_len, rsactx);
else { else {
_libssh2_error(session, LIBSSH2_ERROR_PROTO, _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Unsupported hash digest length"); "Unsupported hash digest length");
@@ -2097,7 +2125,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx,
unsigned char *temp_buffer = NULL; unsigned char *temp_buffer = NULL;
unsigned char *out_buffer = NULL; unsigned char *out_buffer = NULL;
ECDSA_SIG *sig = ECDSA_do_sign(hash, hash_len, ec_ctx); ECDSA_SIG *sig = ECDSA_do_sign(hash, (int) hash_len, ec_ctx);
if(sig == NULL) if(sig == NULL)
return -1; return -1;
#ifdef HAVE_OPAQUE_STRUCTS #ifdef HAVE_OPAQUE_STRUCTS
@@ -2585,7 +2613,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session,
goto fail; goto fail;
} }
BN_bin2bn(exponent, exponentlen, bn_exponent); BN_bin2bn(exponent, (int) exponentlen, bn_exponent);
rc = (EC_KEY_set_private_key(ec_key, bn_exponent) != 1); rc = (EC_KEY_set_private_key(ec_key, bn_exponent) != 1);
if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) { if(rc == 0 && ec_key != NULL && pubkeydata != NULL && method != NULL) {
@@ -3059,7 +3087,7 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key,
goto clean_exit; goto clean_exit;
} }
BN_bin2bn(secret, secret_len, *k); BN_bin2bn(secret, (int) secret_len, *k);
clean_exit: clean_exit:
@@ -3690,7 +3718,11 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
LIBSSH2_TRACE_AUTH, LIBSSH2_TRACE_AUTH,
"Computing public key from private key.")); "Computing public key from private key."));
bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len); #if OPENSSL_VERSION_NUMBER >= 0x1000200fL
bp = BIO_new_mem_buf(privatekeydata, (int)privatekeydata_len);
#else
bp = BIO_new_mem_buf((char *)privatekeydata, (int)privatekeydata_len);
#endif
if(!bp) if(!bp)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory when" "Unable to allocate memory when"
@@ -3780,7 +3812,11 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session,
LIBSSH2_TRACE_AUTH, LIBSSH2_TRACE_AUTH,
"Computing public key from private key.")); "Computing public key from private key."));
bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len); #if OPENSSL_VERSION_NUMBER >= 0x1000200fL
bp = BIO_new_mem_buf(privatekeydata, (int)privatekeydata_len);
#else
bp = BIO_new_mem_buf((char *)privatekeydata, (int)privatekeydata_len);
#endif
if(!bp) if(!bp)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory when" "Unable to allocate memory when"

View File

@@ -304,15 +304,15 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx);
#define libssh2_hmac_ctx HMAC_CTX * #define libssh2_hmac_ctx HMAC_CTX *
#define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new() #define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new()
#define libssh2_hmac_sha1_init(ctx, key, keylen) \ #define libssh2_hmac_sha1_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, keylen, EVP_sha1(), NULL) HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha1(), NULL)
#define libssh2_hmac_md5_init(ctx, key, keylen) \ #define libssh2_hmac_md5_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, keylen, EVP_md5(), NULL) HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_md5(), NULL)
#define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, keylen, EVP_ripemd160(), NULL) HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_ripemd160(), NULL)
#define libssh2_hmac_sha256_init(ctx, key, keylen) \ #define libssh2_hmac_sha256_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, keylen, EVP_sha256(), NULL) HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha256(), NULL)
#define libssh2_hmac_sha512_init(ctx, key, keylen) \ #define libssh2_hmac_sha512_init(ctx, key, keylen) \
HMAC_Init_ex(*(ctx), key, keylen, EVP_sha512(), NULL) HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL)
#define libssh2_hmac_update(ctx, data, datalen) \ #define libssh2_hmac_update(ctx, data, datalen) \
HMAC_Update(ctx, data, datalen) HMAC_Update(ctx, data, datalen)
@@ -323,15 +323,15 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx);
#define libssh2_hmac_ctx_init(ctx) \ #define libssh2_hmac_ctx_init(ctx) \
HMAC_CTX_init(&ctx) HMAC_CTX_init(&ctx)
#define libssh2_hmac_sha1_init(ctx, key, keylen) \ #define libssh2_hmac_sha1_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, keylen, EVP_sha1(), NULL) HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha1(), NULL)
#define libssh2_hmac_md5_init(ctx, key, keylen) \ #define libssh2_hmac_md5_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, keylen, EVP_md5(), NULL) HMAC_Init_ex(ctx, key, (int)keylen, EVP_md5(), NULL)
#define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ #define libssh2_hmac_ripemd160_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, keylen, EVP_ripemd160(), NULL) HMAC_Init_ex(ctx, key, (int)keylen, EVP_ripemd160(), NULL)
#define libssh2_hmac_sha256_init(ctx, key, keylen) \ #define libssh2_hmac_sha256_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, keylen, EVP_sha256(), NULL) HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha256(), NULL)
#define libssh2_hmac_sha512_init(ctx, key, keylen) \ #define libssh2_hmac_sha512_init(ctx, key, keylen) \
HMAC_Init_ex(ctx, key, keylen, EVP_sha512(), NULL) HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha512(), NULL)
#define libssh2_hmac_update(ctx, data, datalen) \ #define libssh2_hmac_update(ctx, data, datalen) \
HMAC_Update(&(ctx), data, datalen) HMAC_Update(&(ctx), data, datalen)
@@ -404,7 +404,7 @@ libssh2_curve_type;
#define _libssh2_bn_init() BN_new() #define _libssh2_bn_init() BN_new()
#define _libssh2_bn_init_from_bin() _libssh2_bn_init() #define _libssh2_bn_init_from_bin() _libssh2_bn_init()
#define _libssh2_bn_set_word(bn, val) BN_set_word(bn, val) #define _libssh2_bn_set_word(bn, val) BN_set_word(bn, val)
#define _libssh2_bn_from_bin(bn, len, val) BN_bin2bn(val, len, bn) #define _libssh2_bn_from_bin(bn, len, val) BN_bin2bn(val, (int)len, bn)
#define _libssh2_bn_to_bin(bn, val) BN_bn2bin(bn, val) #define _libssh2_bn_to_bin(bn, val) BN_bn2bin(bn, val)
#define _libssh2_bn_bytes(bn) BN_num_bytes(bn) #define _libssh2_bn_bytes(bn) BN_num_bytes(bn)
#define _libssh2_bn_bits(bn) BN_num_bits(bn) #define _libssh2_bn_bits(bn) BN_num_bits(bn)

View File

@@ -782,7 +782,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
datalen = channelp->remote.window_size - datalen = channelp->remote.window_size -
channelp->read_avail + data_head; channelp->read_avail + data_head;
channelp->remote.window_size -= datalen - data_head; channelp->remote.window_size -= (uint32_t)(datalen -
data_head);
_libssh2_debug((session, LIBSSH2_TRACE_CONN, _libssh2_debug((session, LIBSSH2_TRACE_CONN,
"shrinking window size by %lu bytes to %lu, " "shrinking window size by %lu bytes to %lu, "
"read_avail %lu", "read_avail %lu",

View File

@@ -100,7 +100,8 @@ static const char *crypt_annotation = "Proc-Type: 4,ENCRYPTED";
static unsigned char hex_decode(char digit) static unsigned char hex_decode(char digit)
{ {
return (digit >= 'A') ? 0xA + (digit - 'A') : (digit - '0'); return (unsigned char)
((digit >= 'A') ? (0xA + (digit - 'A')) : (digit - '0'));
} }
int int
@@ -157,7 +158,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session,
/* Decode IV from hex */ /* Decode IV from hex */
for(i = 0; i < method->iv_len; ++i) { for(i = 0; i < method->iv_len; ++i) {
iv[i] = hex_decode(iv[2*i]) << 4; iv[i] = (unsigned char)(hex_decode(iv[2*i]) << 4);
iv[i] |= hex_decode(iv[2*i + 1]); iv[i] |= hex_decode(iv[2*i + 1]);
} }
@@ -391,7 +392,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
/* decode file */ /* decode file */
if(libssh2_base64_decode(session, (char **)&f, &f_len, if(libssh2_base64_decode(session, (char **)&f, &f_len,
b64data, b64datalen)) { b64data, (unsigned int)b64datalen)) {
ret = -1; ret = -1;
goto out; goto out;
} }

View File

@@ -272,7 +272,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
return 0; return 0;
publickey_status_error(pkey, session, status); publickey_status_error(pkey, session, status);
return -1; goto err_exit;
} }
default: default:
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
@@ -287,7 +287,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
data = NULL; data = NULL;
} }
} }
/* never reached, but include `return` to silence compiler warnings */ err_exit:
return -1; return -1;
} }
@@ -639,25 +639,25 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
} }
pkey->add_s = pkey->add_packet; pkey->add_s = pkey->add_packet;
_libssh2_htonu32(pkey->add_s, packet_len - 4); _libssh2_htonu32(pkey->add_s, (uint32_t)(packet_len - 4));
pkey->add_s += 4; pkey->add_s += 4;
_libssh2_htonu32(pkey->add_s, sizeof("add") - 1); _libssh2_htonu32(pkey->add_s, sizeof("add") - 1);
pkey->add_s += 4; pkey->add_s += 4;
memcpy(pkey->add_s, "add", sizeof("add") - 1); memcpy(pkey->add_s, "add", sizeof("add") - 1);
pkey->add_s += sizeof("add") - 1; pkey->add_s += sizeof("add") - 1;
if(pkey->version == 1) { if(pkey->version == 1) {
_libssh2_htonu32(pkey->add_s, comment_len); _libssh2_htonu32(pkey->add_s, (uint32_t)comment_len);
pkey->add_s += 4; pkey->add_s += 4;
if(comment) { if(comment) {
memcpy(pkey->add_s, comment, comment_len); memcpy(pkey->add_s, comment, comment_len);
pkey->add_s += comment_len; pkey->add_s += comment_len;
} }
_libssh2_htonu32(pkey->add_s, name_len); _libssh2_htonu32(pkey->add_s, (uint32_t)name_len);
pkey->add_s += 4; pkey->add_s += 4;
memcpy(pkey->add_s, name, name_len); memcpy(pkey->add_s, name, name_len);
pkey->add_s += name_len; pkey->add_s += name_len;
_libssh2_htonu32(pkey->add_s, blob_len); _libssh2_htonu32(pkey->add_s, (uint32_t)blob_len);
pkey->add_s += 4; pkey->add_s += 4;
memcpy(pkey->add_s, blob, blob_len); memcpy(pkey->add_s, blob, blob_len);
pkey->add_s += blob_len; pkey->add_s += blob_len;
@@ -665,23 +665,23 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
else { else {
/* Version == 2 */ /* Version == 2 */
_libssh2_htonu32(pkey->add_s, name_len); _libssh2_htonu32(pkey->add_s, (uint32_t)name_len);
pkey->add_s += 4; pkey->add_s += 4;
memcpy(pkey->add_s, name, name_len); memcpy(pkey->add_s, name, name_len);
pkey->add_s += name_len; pkey->add_s += name_len;
_libssh2_htonu32(pkey->add_s, blob_len); _libssh2_htonu32(pkey->add_s, (uint32_t)blob_len);
pkey->add_s += 4; pkey->add_s += 4;
memcpy(pkey->add_s, blob, blob_len); memcpy(pkey->add_s, blob, blob_len);
pkey->add_s += blob_len; pkey->add_s += blob_len;
*(pkey->add_s++) = overwrite ? 0x01 : 0; *(pkey->add_s++) = overwrite ? 0x01 : 0;
_libssh2_htonu32(pkey->add_s, num_attrs); _libssh2_htonu32(pkey->add_s, (uint32_t)num_attrs);
pkey->add_s += 4; pkey->add_s += 4;
for(i = 0; i < num_attrs; i++) { for(i = 0; i < num_attrs; i++) {
_libssh2_htonu32(pkey->add_s, attrs[i].name_len); _libssh2_htonu32(pkey->add_s, (uint32_t)attrs[i].name_len);
pkey->add_s += 4; pkey->add_s += 4;
memcpy(pkey->add_s, attrs[i].name, attrs[i].name_len); memcpy(pkey->add_s, attrs[i].name, attrs[i].name_len);
pkey->add_s += attrs[i].name_len; pkey->add_s += attrs[i].name_len;
_libssh2_htonu32(pkey->add_s, attrs[i].value_len); _libssh2_htonu32(pkey->add_s, (uint32_t)attrs[i].value_len);
pkey->add_s += 4; pkey->add_s += 4;
memcpy(pkey->add_s, attrs[i].value, attrs[i].value_len); memcpy(pkey->add_s, attrs[i].value, attrs[i].value_len);
pkey->add_s += attrs[i].value_len; pkey->add_s += attrs[i].value_len;
@@ -758,17 +758,17 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
} }
pkey->remove_s = pkey->remove_packet; pkey->remove_s = pkey->remove_packet;
_libssh2_htonu32(pkey->remove_s, packet_len - 4); _libssh2_htonu32(pkey->remove_s, (uint32_t)(packet_len - 4));
pkey->remove_s += 4; pkey->remove_s += 4;
_libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1); _libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1);
pkey->remove_s += 4; pkey->remove_s += 4;
memcpy(pkey->remove_s, "remove", sizeof("remove") - 1); memcpy(pkey->remove_s, "remove", sizeof("remove") - 1);
pkey->remove_s += sizeof("remove") - 1; pkey->remove_s += sizeof("remove") - 1;
_libssh2_htonu32(pkey->remove_s, name_len); _libssh2_htonu32(pkey->remove_s, (uint32_t)name_len);
pkey->remove_s += 4; pkey->remove_s += 4;
memcpy(pkey->remove_s, name, name_len); memcpy(pkey->remove_s, name, name_len);
pkey->remove_s += name_len; pkey->remove_s += name_len;
_libssh2_htonu32(pkey->remove_s, blob_len); _libssh2_htonu32(pkey->remove_s, (uint32_t)blob_len);
pkey->remove_s += 4; pkey->remove_s += 4;
memcpy(pkey->remove_s, blob, blob_len); memcpy(pkey->remove_s, blob, blob_len);
pkey->remove_s += blob_len; pkey->remove_s += blob_len;
@@ -835,7 +835,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
pkey->listFetch_data = NULL; pkey->listFetch_data = NULL;
pkey->listFetch_s = pkey->listFetch_buffer; pkey->listFetch_s = pkey->listFetch_buffer;
_libssh2_htonu32(pkey->listFetch_s, buffer_len - 4); _libssh2_htonu32(pkey->listFetch_s, (uint32_t)(buffer_len - 4));
pkey->listFetch_s += 4; pkey->listFetch_s += 4;
_libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1); _libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1);
pkey->listFetch_s += 4; pkey->listFetch_s += 4;

View File

@@ -122,9 +122,9 @@
until then it is kept static and in this source file. until then it is kept static and in this source file.
*/ */
static unsigned static size_t
shell_quotearg(const char *path, unsigned char *buf, shell_quotearg(const char *path, unsigned char *buf,
unsigned bufsize) size_t bufsize)
{ {
const char *src; const char *src;
unsigned char *dst, *endp; unsigned char *dst, *endp;
@@ -270,7 +270,7 @@ shell_quotearg(const char *path, unsigned char *buf,
static LIBSSH2_CHANNEL * static LIBSSH2_CHANNEL *
scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
{ {
int cmd_len; size_t cmd_len;
int rc; int rc;
int tmp_err_code; int tmp_err_code;
const char *tmp_err_msg; const char *tmp_err_msg;
@@ -364,7 +364,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
} }
if(session->scpRecv_state == libssh2_NB_state_sent1) { if(session->scpRecv_state == libssh2_NB_state_sent1) {
rc = _libssh2_channel_write(session->scpRecv_channel, 0, rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
session->scpRecv_response, 1); session->scpRecv_response, 1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
@@ -388,10 +388,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
unsigned char *s, *p; unsigned char *s, *p;
if(session->scpRecv_state == libssh2_NB_state_sent2) { if(session->scpRecv_state == libssh2_NB_state_sent2) {
rc = _libssh2_channel_read(session->scpRecv_channel, 0, rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0,
(char *) session-> (char *) session->
scpRecv_response + scpRecv_response +
session->scpRecv_response_len, 1); session->scpRecv_response_len,
1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for SCP response"); "Would block waiting for SCP response");
@@ -550,7 +551,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
} }
if(session->scpRecv_state == libssh2_NB_state_sent3) { if(session->scpRecv_state == libssh2_NB_state_sent3) {
rc = _libssh2_channel_write(session->scpRecv_channel, 0, rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
session->scpRecv_response, 1); session->scpRecv_response, 1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
@@ -587,10 +588,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
char *s, *p, *e = NULL; char *s, *p, *e = NULL;
if(session->scpRecv_state == libssh2_NB_state_sent5) { if(session->scpRecv_state == libssh2_NB_state_sent5) {
rc = _libssh2_channel_read(session->scpRecv_channel, 0, rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0,
(char *) session-> (char *) session->
scpRecv_response + scpRecv_response +
session->scpRecv_response_len, 1); session->scpRecv_response_len,
1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for SCP response"); "Would block waiting for SCP response");
@@ -714,7 +716,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
} }
if(session->scpRecv_state == libssh2_NB_state_sent6) { if(session->scpRecv_state == libssh2_NB_state_sent6) {
rc = _libssh2_channel_write(session->scpRecv_channel, 0, rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
session->scpRecv_response, 1); session->scpRecv_response, 1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
@@ -833,7 +835,7 @@ static LIBSSH2_CHANNEL *
scp_send(LIBSSH2_SESSION * session, const char *path, int mode, scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
libssh2_int64_t size, time_t mtime, time_t atime) libssh2_int64_t size, time_t mtime, time_t atime)
{ {
int cmd_len; size_t cmd_len;
int rc; int rc;
int tmp_err_code; int tmp_err_code;
const char *tmp_err_msg; const char *tmp_err_msg;
@@ -923,7 +925,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
if(session->scpSend_state == libssh2_NB_state_sent1) { if(session->scpSend_state == libssh2_NB_state_sent1) {
/* Wait for ACK */ /* Wait for ACK */
rc = _libssh2_channel_read(session->scpSend_channel, 0, rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
(char *) session->scpSend_response, 1); (char *) session->scpSend_response, 1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
@@ -958,7 +960,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
/* Send mtime and atime to be used for file */ /* Send mtime and atime to be used for file */
if(mtime || atime) { if(mtime || atime) {
if(session->scpSend_state == libssh2_NB_state_sent2) { if(session->scpSend_state == libssh2_NB_state_sent2) {
rc = _libssh2_channel_write(session->scpSend_channel, 0, rc = (int)_libssh2_channel_write(session->scpSend_channel, 0,
session->scpSend_response, session->scpSend_response,
session->scpSend_response_len); session->scpSend_response_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
@@ -977,8 +979,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
if(session->scpSend_state == libssh2_NB_state_sent3) { if(session->scpSend_state == libssh2_NB_state_sent3) {
/* Wait for ACK */ /* Wait for ACK */
rc = _libssh2_channel_read(session->scpSend_channel, 0, rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
(char *) session->scpSend_response, 1); (char *) session->scpSend_response,
1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response"); "Would block waiting for response");
@@ -1026,7 +1029,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
} }
if(session->scpSend_state == libssh2_NB_state_sent5) { if(session->scpSend_state == libssh2_NB_state_sent5) {
rc = _libssh2_channel_write(session->scpSend_channel, 0, rc = (int)_libssh2_channel_write(session->scpSend_channel, 0,
session->scpSend_response, session->scpSend_response,
session->scpSend_response_len); session->scpSend_response_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
@@ -1045,8 +1048,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
if(session->scpSend_state == libssh2_NB_state_sent6) { if(session->scpSend_state == libssh2_NB_state_sent6) {
/* Wait for ACK */ /* Wait for ACK */
rc = _libssh2_channel_read(session->scpSend_channel, 0, rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
(char *) session->scpSend_response, 1); (char *) session->scpSend_response,
1);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response"); "Would block waiting for response");
@@ -1074,7 +1078,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
} }
/* Read the remote error message */ /* Read the remote error message */
rc = _libssh2_channel_read(session->scpSend_channel, 0, rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
err_msg, err_len); err_msg, err_len);
if(rc > 0) { if(rc > 0) {
err_msg[err_len] = 0; err_msg[err_len] = 0;

View File

@@ -330,6 +330,8 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */
#endif #endif
#ifdef HAVE_DISABLED_NONBLOCKING #ifdef HAVE_DISABLED_NONBLOCKING
(void)sockfd;
(void)nonblock;
return 0; /* returns success */ return 0; /* returns success */
#undef SETBLOCK #undef SETBLOCK
#define SETBLOCK 6 #define SETBLOCK 6
@@ -409,6 +411,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd)
#endif #endif
#ifdef HAVE_DISABLED_NONBLOCKING #ifdef HAVE_DISABLED_NONBLOCKING
(void)sockfd;
return 1; /* returns blocking */ return 1; /* returns blocking */
#undef GETBLOCK #undef GETBLOCK
#define GETBLOCK 7 #define GETBLOCK 7
@@ -651,7 +654,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND) if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
sockets[0].events |= POLLOUT; sockets[0].events |= POLLOUT;
rc = poll(sockets, 1, has_timeout?ms_to_next: -1); rc = poll(sockets, 1, has_timeout ? (int)ms_to_next : -1);
} }
#else #else
{ {
@@ -662,7 +665,11 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
struct timeval tv; struct timeval tv;
tv.tv_sec = ms_to_next / 1000; tv.tv_sec = ms_to_next / 1000;
#ifdef WIN32
tv.tv_usec = (long)((ms_to_next - tv.tv_sec*1000) * 1000);
#else
tv.tv_usec = (ms_to_next - tv.tv_sec*1000) * 1000; tv.tv_usec = (ms_to_next - tv.tv_sec*1000) * 1000;
#endif
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND) { if(dir & LIBSSH2_SESSION_BLOCK_INBOUND) {
FD_ZERO(&rfd); FD_ZERO(&rfd);
@@ -676,7 +683,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
writefd = &wfd; writefd = &wfd;
} }
rc = select(session->socket_fd + 1, readfd, writefd, NULL, rc = select((int)(session->socket_fd + 1), readfd, writefd, NULL,
has_timeout ? &tv : NULL); has_timeout ? &tv : NULL);
} }
#endif #endif
@@ -1538,7 +1545,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
switch(fds[i].type) { switch(fds[i].type) {
case LIBSSH2_POLLFD_SOCKET: case LIBSSH2_POLLFD_SOCKET:
sockets[i].fd = fds[i].fd.socket; sockets[i].fd = fds[i].fd.socket;
sockets[i].events = fds[i].events; sockets[i].events = (short)fds[i].events;
sockets[i].revents = 0; sockets[i].revents = 0;
break; break;
@@ -1705,7 +1712,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
struct timeval tv_begin, tv_end; struct timeval tv_begin, tv_end;
_libssh2_gettimeofday((struct timeval *) &tv_begin, NULL); _libssh2_gettimeofday((struct timeval *) &tv_begin, NULL);
sysret = poll(sockets, nfds, timeout_remaining); sysret = poll(sockets, nfds, (int)timeout_remaining);
_libssh2_gettimeofday((struct timeval *) &tv_end, NULL); _libssh2_gettimeofday((struct timeval *) &tv_end, NULL);
timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000; timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000;
timeout_remaining -= (tv_end.tv_usec - tv_begin.tv_usec) / 1000; timeout_remaining -= (tv_end.tv_usec - tv_begin.tv_usec) / 1000;
@@ -1714,7 +1721,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
/* If the platform doesn't support gettimeofday, /* If the platform doesn't support gettimeofday,
* then just make the call non-blocking and walk away * then just make the call non-blocking and walk away
*/ */
sysret = poll(sockets, nfds, timeout_remaining); sysret = poll(sockets, nfds, (int)timeout_remaining);
timeout_remaining = 0; timeout_remaining = 0;
#endif /* HAVE_GETTIMEOFDAY */ #endif /* HAVE_GETTIMEOFDAY */
@@ -1768,7 +1775,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
struct timeval tv_begin, tv_end; struct timeval tv_begin, tv_end;
_libssh2_gettimeofday((struct timeval *) &tv_begin, NULL); _libssh2_gettimeofday((struct timeval *) &tv_begin, NULL);
sysret = select(maxfd + 1, &rfds, &wfds, NULL, &tv); sysret = select((int)(maxfd + 1), &rfds, &wfds, NULL, &tv);
_libssh2_gettimeofday((struct timeval *) &tv_end, NULL); _libssh2_gettimeofday((struct timeval *) &tv_end, NULL);
timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000; timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 1000;
@@ -1778,7 +1785,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
/* If the platform doesn't support gettimeofday, /* If the platform doesn't support gettimeofday,
* then just make the call non-blocking and walk away * then just make the call non-blocking and walk away
*/ */
sysret = select(maxfd + 1, &rfds, &wfds, NULL, &tv); sysret = select((int)(maxfd + 1), &rfds, &wfds, NULL, &tv);
timeout_remaining = 0; timeout_remaining = 0;
#endif #endif

View File

@@ -649,24 +649,24 @@ sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs)
return 4; return 4;
} }
_libssh2_store_u32(&s, attrs->flags & flag_mask); _libssh2_store_u32(&s, (uint32_t)(attrs->flags & flag_mask));
if(attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) { if(attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
_libssh2_store_u64(&s, attrs->filesize); _libssh2_store_u64(&s, attrs->filesize);
} }
if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) { if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
_libssh2_store_u32(&s, attrs->uid); _libssh2_store_u32(&s, (uint32_t)attrs->uid);
_libssh2_store_u32(&s, attrs->gid); _libssh2_store_u32(&s, (uint32_t)attrs->gid);
} }
if(attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) { if(attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
_libssh2_store_u32(&s, attrs->permissions); _libssh2_store_u32(&s, (uint32_t)attrs->permissions);
} }
if(attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) { if(attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
_libssh2_store_u32(&s, attrs->atime); _libssh2_store_u32(&s, (uint32_t)attrs->atime);
_libssh2_store_u32(&s, attrs->mtime); _libssh2_store_u32(&s, (uint32_t)attrs->mtime);
} }
return (s - p); return (s - p);
@@ -1118,9 +1118,9 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
if(sftp->open_state == libssh2_NB_state_idle) { if(sftp->open_state == libssh2_NB_state_idle) {
/* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) + /* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) +
flags(4) */ flags(4) */
sftp->open_packet_len = filename_len + 13 + sftp->open_packet_len = (uint32_t)(filename_len + 13 +
(open_file? (4 + (open_file? (4 +
sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0); sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0));
/* surprise! this starts out with nothing sent */ /* surprise! this starts out with nothing sent */
sftp->open_packet_sent = 0; sftp->open_packet_sent = 0;
@@ -1185,7 +1185,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
} }
if(sftp->open_state == libssh2_NB_state_sent) { if(sftp->open_state == libssh2_NB_state_sent) {
size_t data_len; size_t data_len = 0;
unsigned char *data; unsigned char *data;
static const unsigned char fopen_responses[2] = static const unsigned char fopen_responses[2] =
{ SSH_FXP_HANDLE, SSH_FXP_STATUS }; { SSH_FXP_HANDLE, SSH_FXP_STATUS };
@@ -1453,7 +1453,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
allows, expand it! */ allows, expand it! */
rc = _libssh2_channel_receive_window_adjust(sftp->channel, rc = _libssh2_channel_receive_window_adjust(sftp->channel,
max_read_ahead*8, (uint32_t)(max_read_ahead * 8),
1, NULL); 1, NULL);
/* if this returns EAGAIN, we will get back to this function /* if this returns EAGAIN, we will get back to this function
at next call */ at next call */
@@ -1469,12 +1469,12 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
/* 25 = packet_len(4) + packet_type(1) + request_id(4) + /* 25 = packet_len(4) + packet_type(1) + request_id(4) +
handle_len(4) + offset(8) + count(4) */ handle_len(4) + offset(8) + count(4) */
uint32_t packet_len = (uint32_t)handle->handle_len + 25; uint32_t packet_len = (uint32_t)(handle->handle_len + 25);
uint32_t request_id; uint32_t request_id;
uint32_t size = count; uint32_t size = (uint32_t)count;
if(size < buffer_size) if(size < buffer_size)
size = buffer_size; size = (uint32_t)buffer_size;
if(size > MAX_SFTP_READ_SIZE) if(size > MAX_SFTP_READ_SIZE)
size = MAX_SFTP_READ_SIZE; size = MAX_SFTP_READ_SIZE;
@@ -1668,7 +1668,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
/* getting the full packet would overflow the buffer, so /* getting the full packet would overflow the buffer, so
only get the correct amount and keep the remainder */ only get the correct amount and keep the remainder */
rc32 = (uint32_t)buffer_size - bytes_in_buffer; rc32 = (uint32_t)(buffer_size - bytes_in_buffer);
/* store data to keep for next call */ /* store data to keep for next call */
filep->data = data; filep->data = data;
@@ -1755,7 +1755,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
size_t data_len = 0; size_t data_len = 0;
uint32_t num_names; uint32_t num_names;
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */
uint32_t packet_len = handle->handle_len + 13; uint32_t packet_len = (uint32_t)(handle->handle_len + 13);
unsigned char *s, *data; unsigned char *s, *data;
static const unsigned char read_responses[2] = { static const unsigned char read_responses[2] = {
SSH_FXP_NAME, SSH_FXP_STATUS }; SSH_FXP_NAME, SSH_FXP_STATUS };
@@ -2057,12 +2057,12 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
while(count) { while(count) {
/* TODO: Possibly this should have some logic to prevent a very /* TODO: Possibly this should have some logic to prevent a very
very small fraction to be left but lets ignore that for now */ very small fraction to be left but lets ignore that for now */
uint32_t size = MIN(MAX_SFTP_OUTGOING_SIZE, count); uint32_t size = (uint32_t)(MIN(MAX_SFTP_OUTGOING_SIZE, count));
uint32_t request_id; uint32_t request_id;
/* 25 = packet_len(4) + packet_type(1) + request_id(4) + /* 25 = packet_len(4) + packet_type(1) + request_id(4) +
handle_len(4) + offset(8) + count(4) */ handle_len(4) + offset(8) + count(4) */
packet_len = handle->handle_len + size + 25; packet_len = (uint32_t)(handle->handle_len + size + 25);
chunk = LIBSSH2_ALLOC(session, packet_len + chunk = LIBSSH2_ALLOC(session, packet_len +
sizeof(struct sftp_pipeline_chunk)); sizeof(struct sftp_pipeline_chunk));
@@ -2245,7 +2245,7 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session = channel->session;
/* 34 = packet_len(4) + packet_type(1) + request_id(4) + /* 34 = packet_len(4) + packet_type(1) + request_id(4) +
string_len(4) + strlen("fsync@openssh.com")(17) + handle_len(4) */ string_len(4) + strlen("fsync@openssh.com")(17) + handle_len(4) */
uint32_t packet_len = handle->handle_len + 34; uint32_t packet_len = (uint32_t)(handle->handle_len + 34);
size_t data_len = 0; size_t data_len = 0;
unsigned char *packet, *s, *data = NULL; unsigned char *packet, *s, *data = NULL;
ssize_t rc; ssize_t rc;
@@ -2353,8 +2353,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session = channel->session;
size_t data_len = 0; size_t data_len = 0;
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */
uint32_t packet_len = uint32_t packet_len = (uint32_t)(handle->handle_len + 13 +
handle->handle_len + 13 + (setstat ? sftp_attrsize(attrs->flags) : 0); (setstat ? sftp_attrsize(attrs->flags) : 0));
unsigned char *s, *data = NULL; unsigned char *s, *data = NULL;
static const unsigned char fstat_responses[2] = static const unsigned char fstat_responses[2] =
{ SSH_FXP_ATTRS, SSH_FXP_STATUS }; { SSH_FXP_ATTRS, SSH_FXP_STATUS };
@@ -2578,7 +2578,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
LIBSSH2_SESSION *session = channel->session; LIBSSH2_SESSION *session = channel->session;
size_t data_len = 0; size_t data_len = 0;
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */ /* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */
uint32_t packet_len = handle->handle_len + 13; uint32_t packet_len = (uint32_t)(handle->handle_len + 13);
unsigned char *s, *data = NULL; unsigned char *s, *data = NULL;
int rc = 0; int rc = 0;
@@ -2709,7 +2709,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
size_t data_len = 0; size_t data_len = 0;
int retcode; int retcode;
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) */ /* 13 = packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) */
uint32_t packet_len = filename_len + 13; uint32_t packet_len = (uint32_t)(filename_len + 13);
unsigned char *s, *data = NULL; unsigned char *s, *data = NULL;
int rc; int rc;
@@ -2846,7 +2846,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
_libssh2_store_str(&sftp->rename_s, dest_filename, dest_filename_len); _libssh2_store_str(&sftp->rename_s, dest_filename, dest_filename_len);
if(sftp->version >= 5) if(sftp->version >= 5)
_libssh2_store_u32(&sftp->rename_s, flags); _libssh2_store_u32(&sftp->rename_s, (uint32_t)flags);
sftp->rename_state = libssh2_NB_state_created; sftp->rename_state = libssh2_NB_state_created;
} }
@@ -2955,7 +2955,7 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
/* 17 = packet_len(4) + packet_type(1) + request_id(4) + ext_len(4) /* 17 = packet_len(4) + packet_type(1) + request_id(4) + ext_len(4)
+ handle_len (4) */ + handle_len (4) */
/* 20 = strlen ("fstatvfs@openssh.com") */ /* 20 = strlen ("fstatvfs@openssh.com") */
uint32_t packet_len = handle->handle_len + 20 + 17; uint32_t packet_len = (uint32_t)(handle->handle_len + 20 + 17);
unsigned char *packet, *s, *data = NULL; unsigned char *packet, *s, *data = NULL;
ssize_t rc; ssize_t rc;
unsigned int flag; unsigned int flag;
@@ -3252,7 +3252,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
"packet"); "packet");
} }
_libssh2_store_u32(&s, packet_len - 4); _libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
*(s++) = SSH_FXP_MKDIR; *(s++) = SSH_FXP_MKDIR;
sftp->mkdir_request_id = sftp->request_id++; sftp->mkdir_request_id = sftp->request_id++;
_libssh2_store_u32(&s, sftp->mkdir_request_id); _libssh2_store_u32(&s, sftp->mkdir_request_id);
@@ -3359,7 +3359,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
"packet"); "packet");
} }
_libssh2_store_u32(&s, packet_len - 4); _libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
*(s++) = SSH_FXP_RMDIR; *(s++) = SSH_FXP_RMDIR;
sftp->rmdir_request_id = sftp->request_id++; sftp->rmdir_request_id = sftp->request_id++;
_libssh2_store_u32(&s, sftp->rmdir_request_id); _libssh2_store_u32(&s, sftp->rmdir_request_id);
@@ -3467,7 +3467,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
"packet"); "packet");
} }
_libssh2_store_u32(&s, packet_len - 4); _libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
switch(stat_type) { switch(stat_type) {
case LIBSSH2_SFTP_SETSTAT: case LIBSSH2_SFTP_SETSTAT:
@@ -3612,7 +3612,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_SFTP_REALPATH) ? "realpath" : "symlink", LIBSSH2_SFTP_REALPATH) ? "realpath" : "symlink",
path)); path));
_libssh2_store_u32(&s, packet_len - 4); _libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
switch(link_type) { switch(link_type) {
case LIBSSH2_SFTP_REALPATH: case LIBSSH2_SFTP_REALPATH:

View File

@@ -864,7 +864,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
/* store packet_length, which is the size of the whole packet except /* store packet_length, which is the size of the whole packet except
the MAC and the packet_length field itself */ the MAC and the packet_length field itself */
_libssh2_htonu32(p->outbuf, packet_length - 4); _libssh2_htonu32(p->outbuf, (uint32_t)(packet_length - 4));
/* store padding_length */ /* store padding_length */
p->outbuf[4] = (unsigned char)padding_length; p->outbuf[4] = (unsigned char)padding_length;

View File

@@ -611,7 +611,8 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
} }
if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len,
(char *) sp1, sp2 - sp1)) { (const char *) sp1,
(unsigned int)(sp2 - sp1))) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid key data, not base64 encoded"); "Invalid key data, not base64 encoded");
@@ -715,7 +716,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
} }
if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len,
(char *) sp1, sp2 - sp1)) { (const char *) sp1,
(unsigned int)(sp2 - sp1))) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid key data, not base64 encoded"); "Invalid key data, not base64 encoded");
@@ -938,7 +940,7 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
*sig_len = p - *sig; *sig_len = p - *sig;
_libssh2_store_u32(&x, *sig_len - 4); _libssh2_store_u32(&x, (uint32_t)(*sig_len - 4));
} }
else { else {
_libssh2_debug((session, _libssh2_debug((session,
@@ -1144,8 +1146,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
session->userauth_host_packet + session->userauth_host_packet_len; session->userauth_host_packet + session->userauth_host_packet_len;
_libssh2_store_u32(&session->userauth_host_s, _libssh2_store_u32(&session->userauth_host_s,
4 + session->userauth_host_method_len + (uint32_t)(4 + session->userauth_host_method_len +
4 + sig_len); 4 + sig_len));
_libssh2_store_str(&session->userauth_host_s, _libssh2_store_str(&session->userauth_host_s,
(const char *)session->userauth_host_method, (const char *)session->userauth_host_method,
session->userauth_host_method_len); session->userauth_host_method_len);
@@ -1709,8 +1711,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
"sk-ssh-ed25519@openssh.com", "sk-ssh-ed25519@openssh.com",
session->userauth_pblc_method_len) == 0) { session->userauth_pblc_method_len) == 0) {
_libssh2_store_u32(&s, _libssh2_store_u32(&s,
4 + session->userauth_pblc_method_len + (uint32_t)(4 + session->userauth_pblc_method_len +
sig_len); sig_len));
_libssh2_store_str(&s, (const char *)session->userauth_pblc_method, _libssh2_store_str(&s, (const char *)session->userauth_pblc_method,
session->userauth_pblc_method_len); session->userauth_pblc_method_len);
memcpy(s, sig, sig_len); memcpy(s, sig, sig_len);
@@ -1718,8 +1720,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
} }
else { else {
_libssh2_store_u32(&s, _libssh2_store_u32(&s,
4 + session->userauth_pblc_method_len + 4 + (uint32_t)(4 + session->userauth_pblc_method_len +
sig_len); 4 + sig_len));
_libssh2_store_str(&s, (const char *)session->userauth_pblc_method, _libssh2_store_str(&s, (const char *)session->userauth_pblc_method,
session->userauth_pblc_method_len); session->userauth_pblc_method_len);
_libssh2_store_str(&s, (const char *)sig, sig_len); _libssh2_store_str(&s, (const char *)sig, sig_len);

View File

@@ -668,7 +668,7 @@ _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx,
memcpy(data, sig, datalen); memcpy(data, sig, datalen);
ret = BCryptVerifySignature(ctx->hKey, pPaddingInfo, ret = BCryptVerifySignature(ctx->hKey, pPaddingInfo,
hash, hashlen, data, datalen, flags); hash, (ULONG)hashlen, data, datalen, flags);
_libssh2_wincng_safe_free(hash, hashlen); _libssh2_wincng_safe_free(hash, hashlen);
_libssh2_wincng_safe_free(data, datalen); _libssh2_wincng_safe_free(data, datalen);
@@ -2120,13 +2120,13 @@ _libssh2_wincng_bignum_rand(_libssh2_bn *rnd, int bits, int top, int bottom)
bits = 8; bits = 8;
/* fill most significant byte with zero padding */ /* fill most significant byte with zero padding */
bignum[0] &= ((1 << bits) - 1); bignum[0] &= (unsigned char)((1 << bits) - 1);
/* set most significant bits in most significant byte */ /* set most significant bits in most significant byte */
if(top == 0) if(top == 0)
bignum[0] |= (1 << (bits - 1)); bignum[0] |= (unsigned char)(1 << (bits - 1));
else if(top == 1) else if(top == 1)
bignum[0] |= (3 << (bits - 2)); bignum[0] |= (unsigned char)(3 << (bits - 2));
/* make odd by setting first bit in least significant byte */ /* make odd by setting first bit in least significant byte */
if(bottom) if(bottom)
@@ -2551,7 +2551,8 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret,
unsigned char *start, *end; unsigned char *start, *end;
BCRYPT_DH_KEY_BLOB *public_blob = NULL; BCRYPT_DH_KEY_BLOB *public_blob = NULL;
DWORD key_length_bytes = max(f->length, dhctx->dh_params->cbKeyLength); DWORD key_length_bytes = max(f->length, dhctx->dh_params->cbKeyLength);
DWORD public_blob_len = sizeof(*public_blob) + 3 * key_length_bytes; DWORD public_blob_len = (DWORD)(sizeof(*public_blob) +
3 * key_length_bytes);
{ {
/* Populate a BCRYPT_DH_KEY_BLOB; after the header follows the /* Populate a BCRYPT_DH_KEY_BLOB; after the header follows the

View File

@@ -151,7 +151,8 @@ typedef struct __libssh2_wincng_hash_ctx {
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \ (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \
SHA_DIGEST_LENGTH, NULL, 0) == 0) SHA_DIGEST_LENGTH, NULL, 0) == 0)
#define libssh2_sha1_update(ctx, data, datalen) \ #define libssh2_sha1_update(ctx, data, datalen) \
_libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \
(unsigned long) datalen)
#define libssh2_sha1_final(ctx, hash) \ #define libssh2_sha1_final(ctx, hash) \
_libssh2_wincng_hash_final(&ctx, hash) _libssh2_wincng_hash_final(&ctx, hash)
#define libssh2_sha1(data, datalen, hash) \ #define libssh2_sha1(data, datalen, hash) \
@@ -163,29 +164,34 @@ typedef struct __libssh2_wincng_hash_ctx {
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \ (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \
SHA256_DIGEST_LENGTH, NULL, 0) == 0) SHA256_DIGEST_LENGTH, NULL, 0) == 0)
#define libssh2_sha256_update(ctx, data, datalen) \ #define libssh2_sha256_update(ctx, data, datalen) \
_libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \
(unsigned long) datalen)
#define libssh2_sha256_final(ctx, hash) \ #define libssh2_sha256_final(ctx, hash) \
_libssh2_wincng_hash_final(&ctx, hash) _libssh2_wincng_hash_final(&ctx, hash)
#define libssh2_sha256(data, datalen, hash) \ #define libssh2_sha256(data, datalen, hash) \
_libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA256, \ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA256, \
hash, SHA256_DIGEST_LENGTH) hash, SHA256_DIGEST_LENGTH)
#define libssh2_sha384_ctx _libssh2_wincng_hash_ctx #define libssh2_sha384_ctx _libssh2_wincng_hash_ctx
#define libssh2_sha384_init(ctx) \ #define libssh2_sha384_init(ctx) \
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA384, \ (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA384, \
SHA384_DIGEST_LENGTH, NULL, 0) == 0) SHA384_DIGEST_LENGTH, NULL, 0) == 0)
#define libssh2_sha384_update(ctx, data, datalen) \ #define libssh2_sha384_update(ctx, data, datalen) \
_libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \
(unsigned long) datalen)
#define libssh2_sha384_final(ctx, hash) \ #define libssh2_sha384_final(ctx, hash) \
_libssh2_wincng_hash_final(&ctx, hash) _libssh2_wincng_hash_final(&ctx, hash)
#define libssh2_sha384(data, datalen, hash) \ #define libssh2_sha384(data, datalen, hash) \
_libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \
hash, SHA384_DIGEST_LENGTH) hash, SHA384_DIGEST_LENGTH)
#define libssh2_sha512_ctx _libssh2_wincng_hash_ctx #define libssh2_sha512_ctx _libssh2_wincng_hash_ctx
#define libssh2_sha512_init(ctx) \ #define libssh2_sha512_init(ctx) \
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA512, \ (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA512, \
SHA512_DIGEST_LENGTH, NULL, 0) == 0) SHA512_DIGEST_LENGTH, NULL, 0) == 0)
#define libssh2_sha512_update(ctx, data, datalen) \ #define libssh2_sha512_update(ctx, data, datalen) \
_libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \
(unsigned long) datalen)
#define libssh2_sha512_final(ctx, hash) \ #define libssh2_sha512_final(ctx, hash) \
_libssh2_wincng_hash_final(&ctx, hash) _libssh2_wincng_hash_final(&ctx, hash)
#define libssh2_sha512(data, datalen, hash) \ #define libssh2_sha512(data, datalen, hash) \
@@ -197,7 +203,8 @@ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \ (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \
MD5_DIGEST_LENGTH, NULL, 0) == 0) MD5_DIGEST_LENGTH, NULL, 0) == 0)
#define libssh2_md5_update(ctx, data, datalen) \ #define libssh2_md5_update(ctx, data, datalen) \
_libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \
(unsigned long) datalen)
#define libssh2_md5_final(ctx, hash) \ #define libssh2_md5_final(ctx, hash) \
_libssh2_wincng_hash_final(&ctx, hash) _libssh2_wincng_hash_final(&ctx, hash)
#define libssh2_md5(data, datalen, hash) \ #define libssh2_md5(data, datalen, hash) \
@@ -212,20 +219,25 @@ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \
#define libssh2_hmac_ctx_init(ctx) #define libssh2_hmac_ctx_init(ctx)
#define libssh2_hmac_sha1_init(ctx, key, keylen) \ #define libssh2_hmac_sha1_init(ctx, key, keylen) \
_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA1, \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA1, \
SHA_DIGEST_LENGTH, key, keylen) SHA_DIGEST_LENGTH, \
key, (unsigned long) keylen)
#define libssh2_hmac_md5_init(ctx, key, keylen) \ #define libssh2_hmac_md5_init(ctx, key, keylen) \
_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacMD5, \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacMD5, \
MD5_DIGEST_LENGTH, key, keylen) MD5_DIGEST_LENGTH, \
key, (unsigned long) keylen)
#define libssh2_hmac_ripemd160_init(ctx, key, keylen) #define libssh2_hmac_ripemd160_init(ctx, key, keylen)
/* not implemented */ /* not implemented */
#define libssh2_hmac_sha256_init(ctx, key, keylen) \ #define libssh2_hmac_sha256_init(ctx, key, keylen) \
_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA256, \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA256, \
SHA256_DIGEST_LENGTH, key, keylen) SHA256_DIGEST_LENGTH, \
key, (unsigned long) keylen)
#define libssh2_hmac_sha512_init(ctx, key, keylen) \ #define libssh2_hmac_sha512_init(ctx, key, keylen) \
_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA512, \ _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA512, \
SHA512_DIGEST_LENGTH, key, keylen) SHA512_DIGEST_LENGTH, \
key, (unsigned long) keylen)
#define libssh2_hmac_update(ctx, data, datalen) \ #define libssh2_hmac_update(ctx, data, datalen) \
_libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) _libssh2_wincng_hash_update(&ctx, (const unsigned char *) data, \
(unsigned long) datalen)
#define libssh2_hmac_final(ctx, hash) \ #define libssh2_hmac_final(ctx, hash) \
_libssh2_wincng_hmac_final(&ctx, hash) _libssh2_wincng_hmac_final(&ctx, hash)
#define libssh2_hmac_cleanup(ctx) \ #define libssh2_hmac_cleanup(ctx) \
@@ -396,7 +408,7 @@ _libssh2_bn *_libssh2_wincng_bignum_init(void);
#define _libssh2_bn_set_word(bn, word) \ #define _libssh2_bn_set_word(bn, word) \
_libssh2_wincng_bignum_set_word(bn, word) _libssh2_wincng_bignum_set_word(bn, word)
#define _libssh2_bn_from_bin(bn, len, bin) \ #define _libssh2_bn_from_bin(bn, len, bin) \
_libssh2_wincng_bignum_from_bin(bn, len, bin) _libssh2_wincng_bignum_from_bin(bn, (unsigned long) len, bin)
#define _libssh2_bn_to_bin(bn, bin) \ #define _libssh2_bn_to_bin(bn, bin) \
_libssh2_wincng_bignum_to_bin(bn, bin) _libssh2_wincng_bignum_to_bin(bn, bin)
#define _libssh2_bn_bytes(bn) bn->length #define _libssh2_bn_bytes(bn) bn->length