mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-20 02:42:09 +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:
26
src/agent.c
26
src/agent.c
@@ -131,10 +131,10 @@ agent_connect_unix(LIBSSH2_AGENT *agent)
|
||||
}
|
||||
|
||||
#define RECV_SEND_ALL(func, socket, buffer, length, flags, abstract) \
|
||||
int rc; \
|
||||
size_t finished = 0; \
|
||||
\
|
||||
while(finished < length) { \
|
||||
ssize_t rc; \
|
||||
rc = func(socket, \
|
||||
(char *)buffer + finished, length - finished, \
|
||||
flags, abstract); \
|
||||
@@ -170,9 +170,10 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
|
||||
|
||||
/* Send the length of the request */
|
||||
if(transctx->state == agent_NB_state_request_created) {
|
||||
_libssh2_htonu32(buf, transctx->request_len);
|
||||
rc = _send_all(agent->session->send, agent->fd,
|
||||
buf, sizeof buf, 0, &agent->session->abstract);
|
||||
_libssh2_htonu32(buf, (uint32_t)transctx->request_len);
|
||||
rc = (int)_send_all(agent->session->send, agent->fd,
|
||||
buf, sizeof buf, 0,
|
||||
&agent->session->abstract);
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
else if(rc < 0)
|
||||
@@ -183,8 +184,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
|
||||
|
||||
/* Send the request body */
|
||||
if(transctx->state == agent_NB_state_request_length_sent) {
|
||||
rc = _send_all(agent->session->send, agent->fd, transctx->request,
|
||||
transctx->request_len, 0, &agent->session->abstract);
|
||||
rc = (int)_send_all(agent->session->send, agent->fd,
|
||||
transctx->request, transctx->request_len, 0,
|
||||
&agent->session->abstract);
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
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 */
|
||||
if(transctx->state == agent_NB_state_request_sent) {
|
||||
rc = _recv_all(agent->session->recv, agent->fd,
|
||||
buf, sizeof buf, 0, &agent->session->abstract);
|
||||
rc = (int)_recv_all(agent->session->recv, agent->fd,
|
||||
buf, sizeof buf, 0,
|
||||
&agent->session->abstract);
|
||||
if(rc < 0) {
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
@@ -214,8 +217,9 @@ agent_transact_unix(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
|
||||
|
||||
/* Receive the response body */
|
||||
if(transctx->state == agent_NB_state_response_length_received) {
|
||||
rc = _recv_all(agent->session->recv, agent->fd, transctx->response,
|
||||
transctx->response_len, 0, &agent->session->abstract);
|
||||
rc = (int)_recv_all(agent->session->recv, agent->fd,
|
||||
transctx->response, transctx->response_len, 0,
|
||||
&agent->session->abstract);
|
||||
if(rc < 0) {
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
@@ -311,7 +315,7 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
|
||||
transctx->request_len);
|
||||
|
||||
cds.dwData = PAGEANT_COPYDATA_ID;
|
||||
cds.cbData = 1 + strlen(mapname);
|
||||
cds.cbData = (DWORD)(1 + strlen(mapname));
|
||||
cds.lpData = mapname;
|
||||
|
||||
id = SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds);
|
||||
|
||||
@@ -88,7 +88,7 @@ bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
|
||||
|
||||
/* copy out */
|
||||
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 + 1] = (cdata[i] >> 8) & 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 */
|
||||
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 + 2] = (count >> 8) & 0xff;
|
||||
countsalt[saltlen + 3] = count & 0xff;
|
||||
|
||||
@@ -422,9 +422,9 @@ Blowfish_stream2word(const uint8_t *data, uint16_t databytes,
|
||||
void
|
||||
Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes)
|
||||
{
|
||||
uint16_t i;
|
||||
int i;
|
||||
int k;
|
||||
uint16_t j;
|
||||
uint16_t k;
|
||||
uint32_t temp;
|
||||
uint32_t datal;
|
||||
uint32_t datar;
|
||||
@@ -461,9 +461,9 @@ void
|
||||
Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes,
|
||||
const uint8_t *key, uint16_t keybytes)
|
||||
{
|
||||
uint16_t i;
|
||||
int i;
|
||||
int k;
|
||||
uint16_t j;
|
||||
uint16_t k;
|
||||
uint32_t temp;
|
||||
uint32_t datal;
|
||||
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];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
Blowfish_encipher(c, &l, &r);
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[0] = (uint8_t)(l >> 24 & 0xff);
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[4] = (uint8_t)(r >> 24 & 0xff);
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 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];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
Blowfish_decipher(c, &l, &r);
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[0] = (uint8_t)(l >> 24 & 0xff);
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[4] = (uint8_t)(r >> 24 & 0xff);
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 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];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
Blowfish_encipher(c, &l, &r);
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[0] = (uint8_t)(l >> 24 & 0xff);
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[4] = (uint8_t)(r >> 24 & 0xff);
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 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];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
Blowfish_decipher(c, &l, &r);
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[0] = (uint8_t)(l >> 24 & 0xff);
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[4] = (uint8_t)(r >> 24 & 0xff);
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 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];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
Blowfish_decipher(c, &l, &r);
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[0] = (uint8_t)(l >> 24 & 0xff);
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[4] = (uint8_t)(r >> 24 & 0xff);
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 0xff;
|
||||
data[7] = r & 0xff;
|
||||
|
||||
@@ -470,11 +470,12 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
|
||||
host = "0.0.0.0";
|
||||
|
||||
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)
|
||||
+ port(4) */
|
||||
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 */
|
||||
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",
|
||||
proto_len);
|
||||
|
||||
_libssh2_store_u32(&s, cookie_len);
|
||||
_libssh2_store_u32(&s, (uint32_t)cookie_len);
|
||||
if(auth_cookie) {
|
||||
memcpy(s, auth_cookie, cookie_len);
|
||||
}
|
||||
@@ -1482,7 +1483,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
||||
*(s++) = 0x01;
|
||||
|
||||
if(message)
|
||||
_libssh2_store_u32(&s, message_len);
|
||||
_libssh2_store_u32(&s, (uint32_t)message_len);
|
||||
|
||||
channel->process_state = libssh2_NB_state_created;
|
||||
}
|
||||
@@ -1658,20 +1659,20 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid)
|
||||
}
|
||||
|
||||
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) {
|
||||
int rc =
|
||||
_libssh2_channel_receive_window_adjust(channel,
|
||||
channel->flush_refund_bytes,
|
||||
1, NULL);
|
||||
(uint32_t)channel->flush_refund_bytes,
|
||||
1, NULL);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||
return rc;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
BLOCK_ADJUST(rc, channel->session,
|
||||
_libssh2_channel_receive_window_adjust(channel, adj,
|
||||
_libssh2_channel_receive_window_adjust(channel,
|
||||
(uint32_t)adj,
|
||||
force, &window));
|
||||
|
||||
/* 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;
|
||||
|
||||
BLOCK_ADJUST(rc, channel->session,
|
||||
_libssh2_channel_receive_window_adjust(channel, adj, force,
|
||||
window));
|
||||
_libssh2_channel_receive_window_adjust(channel,
|
||||
(uint32_t)adj,
|
||||
force, window));
|
||||
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_initial / 4 * 3 + buflen) ) {
|
||||
|
||||
uint32_t adjustment = channel->remote.window_size_initial + buflen -
|
||||
channel->remote.window_size;
|
||||
uint32_t adjustment = (uint32_t)(channel->remote.window_size_initial +
|
||||
buflen - channel->remote.window_size);
|
||||
if(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->remote.window_size -= bytes_read;
|
||||
channel->remote.window_size -= (uint32_t)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) {
|
||||
BLOCK_ADJUST(rc, channel->session,
|
||||
_libssh2_channel_receive_window_adjust(channel, buflen,
|
||||
1, NULL));
|
||||
_libssh2_channel_receive_window_adjust(channel,
|
||||
(uint32_t)buflen, 1, NULL));
|
||||
}
|
||||
|
||||
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
|
||||
_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;
|
||||
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_CONN,
|
||||
@@ -2360,7 +2363,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
|
||||
"Unable to send channel data");
|
||||
}
|
||||
/* Shrink local window size */
|
||||
channel->local.window_size -= channel->write_bufwrite;
|
||||
channel->local.window_size -= (uint32_t)channel->write_bufwrite;
|
||||
|
||||
wrote += channel->write_bufwrite;
|
||||
|
||||
@@ -2835,7 +2838,7 @@ libssh2_channel_free(LIBSSH2_CHANNEL *channel)
|
||||
*/
|
||||
LIBSSH2_API unsigned long
|
||||
libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
|
||||
unsigned long *read_avail,
|
||||
/* FIXME: -> size_t */ unsigned long *read_avail,
|
||||
unsigned long *window_size_initial)
|
||||
{
|
||||
if(!channel)
|
||||
@@ -2875,7 +2878,7 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
|
||||
packet = next_packet;
|
||||
}
|
||||
|
||||
*read_avail = bytes_queued;
|
||||
*read_avail = (unsigned long)bytes_queued;
|
||||
}
|
||||
|
||||
return channel->remote.window_size;
|
||||
|
||||
@@ -113,8 +113,11 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
|
||||
if(!_libssh2_eob(&buf))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_rsa_new(&rsactx, e, e_len, n, n_len, NULL, 0,
|
||||
NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0)) {
|
||||
if(_libssh2_rsa_new(&rsactx,
|
||||
e, (unsigned long)e_len,
|
||||
n, (unsigned long)n_len,
|
||||
NULL, 0, NULL, 0, NULL, 0,
|
||||
NULL, 0, NULL, 0, NULL, 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -525,8 +528,12 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
|
||||
if(!_libssh2_eob(&buf))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_dsa_new(&dsactx, p, p_len, q, q_len,
|
||||
g, g_len, y, y_len, NULL, 0)) {
|
||||
if(_libssh2_dsa_new(&dsactx,
|
||||
p, (unsigned long)p_len,
|
||||
q, (unsigned long)q_len,
|
||||
g, (unsigned long)g_len,
|
||||
y, (unsigned long)y_len,
|
||||
NULL, 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
49
src/kex.c
49
src/kex.c
@@ -531,7 +531,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
|
||||
|
||||
if(session->local.banner) {
|
||||
_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,
|
||||
exchange_state->h_sig_comp, 4);
|
||||
_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,
|
||||
strlen((char *) session->remote.banner));
|
||||
(uint32_t)strlen((char *) session->remote.banner));
|
||||
_libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx,
|
||||
exchange_state->h_sig_comp, 4);
|
||||
_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));
|
||||
|
||||
_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,
|
||||
exchange_state->h_sig_comp, 4);
|
||||
_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);
|
||||
|
||||
_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,
|
||||
exchange_state->h_sig_comp, 4);
|
||||
_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);
|
||||
|
||||
ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p,
|
||||
p_len, 1,
|
||||
(int)p_len, 1,
|
||||
(void *)&exchange_hash_ctx,
|
||||
SSH_MSG_KEX_DH_GEX_INIT,
|
||||
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);
|
||||
|
||||
ret = diffie_hellman_sha_algo(session, key_state->g, key_state->p,
|
||||
p_len, 256,
|
||||
(int)p_len, 256,
|
||||
(void *)&exchange_hash_ctx,
|
||||
SSH_MSG_KEX_DH_GEX_INIT,
|
||||
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); \
|
||||
if(session->local.banner) { \
|
||||
_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, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
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, \
|
||||
strlen((char *) session->remote.banner)); \
|
||||
(uint32_t)strlen((char *) session->remote.banner)); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
@@ -1635,7 +1635,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
|
||||
session->remote.banner)); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
session->local.kexinit_len); \
|
||||
(uint32_t)session->local.kexinit_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
@@ -1643,7 +1643,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
|
||||
session->local.kexinit_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
session->remote.kexinit_len); \
|
||||
(uint32_t)session->remote.kexinit_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
@@ -1659,7 +1659,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
|
||||
session->server_hostkey_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
public_key_len); \
|
||||
(uint32_t)public_key_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
@@ -1667,7 +1667,7 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
|
||||
public_key_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
server_public_key_len); \
|
||||
(uint32_t)server_public_key_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
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)
|
||||
type = LIBSSH2_EC_CURVE_NISTP521;
|
||||
else {
|
||||
/* silence:
|
||||
warning C4701: potentially uninitialized local variable 'type' used */
|
||||
#if defined(_MSC_VER)
|
||||
type = (libssh2_curve_type)0;
|
||||
#endif
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
@@ -1907,7 +1912,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
|
||||
goto clean_exit;
|
||||
}
|
||||
_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) {
|
||||
_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,
|
||||
digest_length);
|
||||
session->session_id_len = digest_length;
|
||||
session->session_id_len = (uint32_t)digest_length;
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
||||
"session_id calculated"));
|
||||
}
|
||||
@@ -2298,7 +2303,13 @@ kex_method_ecdh_key_exchange
|
||||
|
||||
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,
|
||||
key_state->data_len,
|
||||
@@ -2541,7 +2552,7 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
goto clean_exit;
|
||||
}
|
||||
_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) {
|
||||
_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,
|
||||
digest_length);
|
||||
session->session_id_len = digest_length;
|
||||
session->session_id_len = (uint32_t)digest_length;
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_KEX,
|
||||
"session_id calculated"));
|
||||
}
|
||||
@@ -3956,7 +3967,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
|
||||
const char *prefs)
|
||||
{
|
||||
char **prefvar, *s, *newprefs;
|
||||
int prefs_len = strlen(prefs);
|
||||
size_t prefs_len = strlen(prefs);
|
||||
const LIBSSH2_COMMON_METHOD **mlist;
|
||||
|
||||
switch(method_type) {
|
||||
@@ -4031,7 +4042,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
|
||||
|
||||
while(s && *s && mlist) {
|
||||
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)) {
|
||||
/* Strip out unsupported method */
|
||||
|
||||
@@ -170,14 +170,14 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
break;
|
||||
case LIBSSH2_KNOWNHOST_TYPE_SHA1:
|
||||
rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen,
|
||||
host, hostlen);
|
||||
host, (unsigned int)hostlen);
|
||||
if(rc)
|
||||
goto error;
|
||||
entry->name = ptr;
|
||||
entry->name_len = ptrlen;
|
||||
|
||||
rc = libssh2_base64_decode(hosts->session, &ptr, &ptrlen,
|
||||
salt, strlen(salt));
|
||||
salt, (unsigned int)strlen(salt));
|
||||
if(rc)
|
||||
goto error;
|
||||
entry->salt = ptr;
|
||||
|
||||
@@ -595,9 +595,10 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
||||
_libssh2_cipher_type(algo),
|
||||
int encrypt, unsigned char *block, size_t blklen)
|
||||
{
|
||||
int cipher = _libssh2_gcry_cipher(algo);
|
||||
int ret;
|
||||
|
||||
(void)algo;
|
||||
|
||||
if(encrypt) {
|
||||
ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen);
|
||||
}
|
||||
|
||||
@@ -227,6 +227,7 @@
|
||||
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
_libssh2_dh_secret(dhctx, secret, f, p)
|
||||
#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 int _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public,
|
||||
_libssh2_bn *g, _libssh2_bn *p,
|
||||
|
||||
@@ -164,10 +164,11 @@ struct iovec {
|
||||
#include "crypto.h"
|
||||
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
|
||||
#include <winsock2.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
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
@@ -201,20 +202,23 @@ struct iovec {
|
||||
#define LIBSSH2_FREE(session, ptr) \
|
||||
session->free((ptr), &(session)->abstract)
|
||||
#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, \
|
||||
language, language_len) \
|
||||
session->ssh_msg_debug((session), (always_display), (message), \
|
||||
(message_len), (language), (language_len), \
|
||||
session->ssh_msg_debug((session), (always_display), \
|
||||
(message), (int)(message_len), \
|
||||
(language), (int)(language_len), \
|
||||
&(session)->abstract)
|
||||
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, \
|
||||
language, language_len) \
|
||||
session->ssh_msg_disconnect((session), (reason), (message), \
|
||||
(message_len), (language), (language_len), \
|
||||
session->ssh_msg_disconnect((session), (reason), \
|
||||
(message), (int)(message_len), \
|
||||
(language), (int)(language_len), \
|
||||
&(session)->abstract)
|
||||
|
||||
#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) \
|
||||
channel->session->x11(((channel)->session), (channel), \
|
||||
(shost), (sport), (&(channel)->session->abstract))
|
||||
@@ -633,7 +637,7 @@ struct _LIBSSH2_SESSION
|
||||
|
||||
/* Agreed Key Exchange Method */
|
||||
const LIBSSH2_KEX_METHOD *kex;
|
||||
unsigned int burn_optimistic_kexinit:1;
|
||||
unsigned int burn_optimistic_kexinit;
|
||||
|
||||
unsigned char *session_id;
|
||||
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 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"
|
||||
#else
|
||||
#define LIBSSH2_INT64_T_FORMAT "lld"
|
||||
|
||||
@@ -126,7 +126,7 @@ _libssh2_mbedtls_cipher_init(_libssh2_cipher_ctx *ctx,
|
||||
if(!ret)
|
||||
ret = mbedtls_cipher_setkey(ctx,
|
||||
secret,
|
||||
mbedtls_cipher_info_get_key_bitlen(cipher_info),
|
||||
(int)mbedtls_cipher_info_get_key_bitlen(cipher_info),
|
||||
op);
|
||||
|
||||
if(!ret)
|
||||
@@ -526,11 +526,11 @@ _libssh2_mbedtls_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
|
||||
|
||||
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||
ret = mbedtls_rsa_pkcs1_verify(rsactx,
|
||||
md_type, hash_len,
|
||||
md_type, (unsigned int)hash_len,
|
||||
hash, sig);
|
||||
#else
|
||||
ret = mbedtls_rsa_pkcs1_verify(rsactx, NULL, NULL, MBEDTLS_RSA_PUBLIC,
|
||||
md_type, hash_len,
|
||||
md_type, (unsigned int)hash_len,
|
||||
hash, sig);
|
||||
#endif
|
||||
free(hash);
|
||||
@@ -558,7 +558,7 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
{
|
||||
int ret;
|
||||
unsigned char *sig;
|
||||
unsigned int sig_len;
|
||||
size_t sig_len;
|
||||
int md_type;
|
||||
(void)hash_len;
|
||||
|
||||
@@ -587,11 +587,11 @@ _libssh2_mbedtls_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
ret = mbedtls_rsa_pkcs1_sign(rsa,
|
||||
mbedtls_ctr_drbg_random,
|
||||
&_libssh2_mbedtls_ctr_drbg,
|
||||
md_type, hash_len,
|
||||
md_type, (unsigned int)hash_len,
|
||||
hash, sig);
|
||||
#else
|
||||
ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE,
|
||||
md_type, hash_len,
|
||||
md_type, (unsigned int)hash_len,
|
||||
hash, sig);
|
||||
#endif
|
||||
}
|
||||
@@ -634,8 +634,8 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session,
|
||||
unsigned char *key;
|
||||
unsigned char *p;
|
||||
|
||||
e_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E));
|
||||
n_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N));
|
||||
e_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E));
|
||||
n_bytes = (int)mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N));
|
||||
|
||||
/* Key form is "ssh-rsa" + e + n. */
|
||||
len = 4 + 7 + 4 + e_bytes + 4 + n_bytes;
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
#define libssh2_hmac_cleanup(pctx) \
|
||||
mbedtls_md_free(pctx)
|
||||
#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) \
|
||||
mbedtls_md_hmac_finish(&ctx, hash)
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
#define libssh2_sha1_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0)
|
||||
#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) \
|
||||
_libssh2_mbedtls_hash_final(&ctx, hash)
|
||||
#define libssh2_sha1(data, datalen, hash) \
|
||||
@@ -168,7 +168,7 @@
|
||||
#define libssh2_sha256_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0)
|
||||
#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) \
|
||||
_libssh2_mbedtls_hash_final(&ctx, hash)
|
||||
#define libssh2_sha256(data, datalen, hash) \
|
||||
@@ -185,7 +185,7 @@
|
||||
#define libssh2_sha384_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0)
|
||||
#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) \
|
||||
_libssh2_mbedtls_hash_final(&ctx, hash)
|
||||
#define libssh2_sha384(data, datalen, hash) \
|
||||
@@ -202,7 +202,7 @@
|
||||
#define libssh2_sha512_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0)
|
||||
#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) \
|
||||
_libssh2_mbedtls_hash_final(&ctx, hash)
|
||||
#define libssh2_sha512(data, datalen, hash) \
|
||||
@@ -219,7 +219,7 @@
|
||||
#define libssh2_md5_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0)
|
||||
#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) \
|
||||
_libssh2_mbedtls_hash_final(&ctx, hash)
|
||||
#define libssh2_md5(data, datalen, hash) \
|
||||
@@ -595,6 +595,8 @@ void
|
||||
_libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx);
|
||||
#endif /* LIBSSH2_ECDSA */
|
||||
|
||||
extern void
|
||||
_libssh2_init_aes_ctr(void);
|
||||
extern void
|
||||
_libssh2_dh_init(_libssh2_dh_ctx *dhctx);
|
||||
extern int
|
||||
|
||||
31
src/misc.c
31
src/misc.c
@@ -79,7 +79,7 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
|
||||
va_start(args, fmt);
|
||||
n = vsnprintf(cp, cp_max_len, fmt, 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
|
||||
|
||||
@@ -230,14 +230,14 @@ _libssh2_ntohu32(const unsigned char *buf)
|
||||
libssh2_uint64_t
|
||||
_libssh2_ntohu64(const unsigned char *buf)
|
||||
{
|
||||
unsigned long msl, lsl;
|
||||
|
||||
msl = ((libssh2_uint64_t)buf[0] << 24) | ((libssh2_uint64_t)buf[1] << 16)
|
||||
| ((libssh2_uint64_t)buf[2] << 8) | (libssh2_uint64_t)buf[3];
|
||||
lsl = ((libssh2_uint64_t)buf[4] << 24) | ((libssh2_uint64_t)buf[5] << 16)
|
||||
| ((libssh2_uint64_t)buf[6] << 8) | (libssh2_uint64_t)buf[7];
|
||||
|
||||
return ((libssh2_uint64_t)msl <<32) | lsl;
|
||||
return ((libssh2_uint64_t)buf[0] << 56)
|
||||
| ((libssh2_uint64_t)buf[1] << 48)
|
||||
| ((libssh2_uint64_t)buf[2] << 40)
|
||||
| ((libssh2_uint64_t)buf[3] << 32)
|
||||
| ((libssh2_uint64_t)buf[4] << 24)
|
||||
| ((libssh2_uint64_t)buf[5] << 16)
|
||||
| ((libssh2_uint64_t)buf[6] << 8)
|
||||
| ((libssh2_uint64_t)buf[7]);
|
||||
}
|
||||
|
||||
/* _libssh2_htonu32
|
||||
@@ -245,7 +245,7 @@ _libssh2_ntohu64(const unsigned char *buf)
|
||||
void
|
||||
_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[2] = (value >> 8) & 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) {}
|
||||
|
||||
extraByte = (len > 0 && (p[0] & 0x80) != 0);
|
||||
_libssh2_store_u32(buf, len + extraByte);
|
||||
_libssh2_store_u32(buf, (uint32_t)(len + extraByte));
|
||||
|
||||
if(extraByte) {
|
||||
*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
|
||||
*/
|
||||
/* FIXME: datalen, src_len -> size_t */
|
||||
LIBSSH2_API int
|
||||
libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
|
||||
unsigned int *datalen, const char *src,
|
||||
@@ -344,15 +345,15 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
|
||||
d[len] = (unsigned char)(v << 2);
|
||||
break;
|
||||
case 1:
|
||||
d[len++] |= v >> 4;
|
||||
d[len++] |= (unsigned char)(v >> 4);
|
||||
d[len] = (unsigned char)(v << 4);
|
||||
break;
|
||||
case 2:
|
||||
d[len++] |= v >> 2;
|
||||
d[len++] |= (unsigned char)(v >> 2);
|
||||
d[len] = (unsigned char)(v << 6);
|
||||
break;
|
||||
case 3:
|
||||
d[len++] |= v;
|
||||
d[len++] |= (unsigned char)v;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
@@ -483,7 +484,7 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format,
|
||||
int len, msglen, buflen = sizeof(buffer);
|
||||
va_list vargs;
|
||||
struct timeval now;
|
||||
static int firstsec;
|
||||
static long firstsec;
|
||||
static const char *const contexts[] = {
|
||||
"Unknown",
|
||||
"Transport",
|
||||
|
||||
112
src/openssl.c
112
src/openssl.c
@@ -119,29 +119,29 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
|
||||
BIGNUM * iqmp = 0;
|
||||
|
||||
e = BN_new();
|
||||
BN_bin2bn(edata, elen, e);
|
||||
BN_bin2bn(edata, (int) elen, e);
|
||||
|
||||
n = BN_new();
|
||||
BN_bin2bn(ndata, nlen, n);
|
||||
BN_bin2bn(ndata, (int) nlen, n);
|
||||
|
||||
if(ddata) {
|
||||
d = BN_new();
|
||||
BN_bin2bn(ddata, dlen, d);
|
||||
BN_bin2bn(ddata, (int) dlen, d);
|
||||
|
||||
p = BN_new();
|
||||
BN_bin2bn(pdata, plen, p);
|
||||
BN_bin2bn(pdata, (int) plen, p);
|
||||
|
||||
q = BN_new();
|
||||
BN_bin2bn(qdata, qlen, q);
|
||||
BN_bin2bn(qdata, (int) qlen, q);
|
||||
|
||||
dmp1 = BN_new();
|
||||
BN_bin2bn(e1data, e1len, dmp1);
|
||||
BN_bin2bn(e1data, (int) e1len, dmp1);
|
||||
|
||||
dmq1 = BN_new();
|
||||
BN_bin2bn(e2data, e2len, dmq1);
|
||||
BN_bin2bn(e2data, (int) e2len, dmq1);
|
||||
|
||||
iqmp = BN_new();
|
||||
BN_bin2bn(coeffdata, coefflen, iqmp);
|
||||
BN_bin2bn(coeffdata, (int) coefflen, iqmp);
|
||||
}
|
||||
|
||||
*rsa = RSA_new();
|
||||
@@ -196,16 +196,23 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx,
|
||||
nid_type = NID_sha512;
|
||||
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 */
|
||||
}
|
||||
|
||||
if(ret != 0) {
|
||||
free(hash);
|
||||
return -1; /* failure */
|
||||
}
|
||||
|
||||
ret = RSA_verify(nid_type, hash, hash_len,
|
||||
(unsigned char *) sig, sig_len, rsactx);
|
||||
ret = RSA_verify(nid_type, hash, (unsigned int) hash_len,
|
||||
(unsigned char *) sig,
|
||||
(unsigned int) sig_len, rsactx);
|
||||
|
||||
free(hash);
|
||||
|
||||
@@ -242,20 +249,20 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx,
|
||||
BIGNUM * priv_key = NULL;
|
||||
|
||||
p_bn = BN_new();
|
||||
BN_bin2bn(p, p_len, p_bn);
|
||||
BN_bin2bn(p, (int) p_len, p_bn);
|
||||
|
||||
q_bn = BN_new();
|
||||
BN_bin2bn(q, q_len, q_bn);
|
||||
BN_bin2bn(q, (int) q_len, q_bn);
|
||||
|
||||
g_bn = BN_new();
|
||||
BN_bin2bn(g, g_len, g_bn);
|
||||
BN_bin2bn(g, (int) g_len, g_bn);
|
||||
|
||||
pub_key = BN_new();
|
||||
BN_bin2bn(y, y_len, pub_key);
|
||||
BN_bin2bn(y, (int) y_len, pub_key);
|
||||
|
||||
if(x_len) {
|
||||
priv_key = BN_new();
|
||||
BN_bin2bn(x, x_len, priv_key);
|
||||
BN_bin2bn(x, (int) x_len, priv_key);
|
||||
}
|
||||
|
||||
*dsactx = DSA_new();
|
||||
@@ -348,6 +355,11 @@ _libssh2_ecdsa_curve_type_from_name(const char *name,
|
||||
else if(strcmp(name, "ecdsa-sha2-nistp521") == 0)
|
||||
type = LIBSSH2_EC_CURVE_NISTP521;
|
||||
else {
|
||||
/* silence:
|
||||
warning C4701: potentially uninitialized local variable 'type' used */
|
||||
#if defined(_MSC_VER)
|
||||
type = (libssh2_curve_type)0;
|
||||
#endif
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
@@ -415,17 +427,17 @@ _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx,
|
||||
BIGNUM *pr = BN_new();
|
||||
BIGNUM *ps = BN_new();
|
||||
|
||||
BN_bin2bn(r, r_len, pr);
|
||||
BN_bin2bn(s, s_len, ps);
|
||||
BN_bin2bn(r, (int) r_len, pr);
|
||||
BN_bin2bn(s, (int) s_len, ps);
|
||||
ECDSA_SIG_set0(ecdsa_sig, pr, ps);
|
||||
|
||||
#else
|
||||
ECDSA_SIG ecdsa_sig_;
|
||||
ECDSA_SIG *ecdsa_sig = &ecdsa_sig_;
|
||||
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();
|
||||
BN_bin2bn(s, s_len, ecdsa_sig_.s);
|
||||
BN_bin2bn(s, (int) s_len, ecdsa_sig_.s);
|
||||
#endif
|
||||
|
||||
if(type == LIBSSH2_EC_CURVE_NISTP256) {
|
||||
@@ -477,9 +489,9 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
||||
(void) encrypt;
|
||||
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
ret = EVP_Cipher(*ctx, buf, block, blocksize);
|
||||
ret = EVP_Cipher(*ctx, buf, block, (unsigned int) blocksize);
|
||||
#else
|
||||
ret = EVP_Cipher(ctx, buf, block, blocksize);
|
||||
ret = EVP_Cipher(ctx, buf, block, (unsigned int) blocksize);
|
||||
#endif
|
||||
|
||||
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || \
|
||||
@@ -525,7 +537,7 @@ void _libssh2_openssl_crypto_exit(void)
|
||||
static int
|
||||
passphrase_cb(char *buf, int size, int rwflag, char *passphrase)
|
||||
{
|
||||
int passphrase_len = strlen(passphrase);
|
||||
int passphrase_len = (int) strlen(passphrase);
|
||||
(void) rwflag;
|
||||
|
||||
if(passphrase_len > (size - 1)) {
|
||||
@@ -551,7 +563,11 @@ read_private_key_from_memory(void **key_ctx,
|
||||
|
||||
*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) {
|
||||
return -1;
|
||||
}
|
||||
@@ -840,9 +856,14 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((rc = _libssh2_rsa_new(&rsa, e, elen, n, nlen, d, dlen, p, plen,
|
||||
q, qlen, NULL, 0, NULL, 0,
|
||||
coeff, coefflen)) != 0) {
|
||||
if((rc = _libssh2_rsa_new(&rsa,
|
||||
e, (unsigned long)elen,
|
||||
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_TRACE_AUTH,
|
||||
"Could not create RSA private key"));
|
||||
@@ -1143,8 +1164,12 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = _libssh2_dsa_new(&dsa, p, plen, q, qlen, g, glen, pub_key, pub_len,
|
||||
priv_key, priv_len);
|
||||
rc = _libssh2_dsa_new(&dsa,
|
||||
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) {
|
||||
_libssh2_debug((session,
|
||||
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_u32(&bufPos, rawKeyLen);
|
||||
_libssh2_store_u32(&bufPos, (uint32_t) rawKeyLen);
|
||||
|
||||
if(EVP_PKEY_get_raw_public_key(pk, bufPos, &rawKeyLen) != 1) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
@@ -2002,11 +2027,14 @@ _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session,
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
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 {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"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 *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)
|
||||
return -1;
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
@@ -2585,7 +2613,7 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session,
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
BN_bin2bn(secret, secret_len, *k);
|
||||
BN_bin2bn(secret, (int) secret_len, *k);
|
||||
|
||||
clean_exit:
|
||||
|
||||
@@ -3690,7 +3718,11 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
LIBSSH2_TRACE_AUTH,
|
||||
"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)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory when"
|
||||
@@ -3780,7 +3812,11 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session,
|
||||
LIBSSH2_TRACE_AUTH,
|
||||
"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)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory when"
|
||||
|
||||
@@ -304,15 +304,15 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx);
|
||||
#define libssh2_hmac_ctx HMAC_CTX *
|
||||
#define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new()
|
||||
#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) \
|
||||
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) \
|
||||
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) \
|
||||
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) \
|
||||
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) \
|
||||
HMAC_Update(ctx, data, datalen)
|
||||
@@ -323,15 +323,15 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx);
|
||||
#define libssh2_hmac_ctx_init(ctx) \
|
||||
HMAC_CTX_init(&ctx)
|
||||
#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) \
|
||||
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) \
|
||||
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) \
|
||||
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) \
|
||||
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) \
|
||||
HMAC_Update(&(ctx), data, datalen)
|
||||
@@ -404,7 +404,7 @@ libssh2_curve_type;
|
||||
#define _libssh2_bn_init() BN_new()
|
||||
#define _libssh2_bn_init_from_bin() _libssh2_bn_init()
|
||||
#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_bytes(bn) BN_num_bytes(bn)
|
||||
#define _libssh2_bn_bits(bn) BN_num_bits(bn)
|
||||
|
||||
@@ -782,7 +782,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
datalen = channelp->remote.window_size -
|
||||
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,
|
||||
"shrinking window size by %lu bytes to %lu, "
|
||||
"read_avail %lu",
|
||||
|
||||
@@ -100,7 +100,8 @@ static const char *crypt_annotation = "Proc-Type: 4,ENCRYPTED";
|
||||
|
||||
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
|
||||
@@ -157,7 +158,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session,
|
||||
|
||||
/* Decode IV from hex */
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -391,7 +392,7 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
|
||||
|
||||
/* decode file */
|
||||
if(libssh2_base64_decode(session, (char **)&f, &f_len,
|
||||
b64data, b64datalen)) {
|
||||
b64data, (unsigned int)b64datalen)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
|
||||
return 0;
|
||||
|
||||
publickey_status_error(pkey, session, status);
|
||||
return -1;
|
||||
goto err_exit;
|
||||
}
|
||||
default:
|
||||
LIBSSH2_FREE(session, data);
|
||||
@@ -287,7 +287,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
|
||||
data = NULL;
|
||||
}
|
||||
}
|
||||
/* never reached, but include `return` to silence compiler warnings */
|
||||
err_exit:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -639,25 +639,25 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
|
||||
}
|
||||
|
||||
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;
|
||||
_libssh2_htonu32(pkey->add_s, sizeof("add") - 1);
|
||||
pkey->add_s += 4;
|
||||
memcpy(pkey->add_s, "add", sizeof("add") - 1);
|
||||
pkey->add_s += sizeof("add") - 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;
|
||||
if(comment) {
|
||||
memcpy(pkey->add_s, comment, 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;
|
||||
memcpy(pkey->add_s, name, 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;
|
||||
memcpy(pkey->add_s, blob, blob_len);
|
||||
pkey->add_s += blob_len;
|
||||
@@ -665,23 +665,23 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
|
||||
else {
|
||||
/* Version == 2 */
|
||||
|
||||
_libssh2_htonu32(pkey->add_s, name_len);
|
||||
_libssh2_htonu32(pkey->add_s, (uint32_t)name_len);
|
||||
pkey->add_s += 4;
|
||||
memcpy(pkey->add_s, name, 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;
|
||||
memcpy(pkey->add_s, blob, blob_len);
|
||||
pkey->add_s += blob_len;
|
||||
*(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;
|
||||
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;
|
||||
memcpy(pkey->add_s, attrs[i].name, 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;
|
||||
memcpy(pkey->add_s, attrs[i].value, 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;
|
||||
_libssh2_htonu32(pkey->remove_s, packet_len - 4);
|
||||
_libssh2_htonu32(pkey->remove_s, (uint32_t)(packet_len - 4));
|
||||
pkey->remove_s += 4;
|
||||
_libssh2_htonu32(pkey->remove_s, sizeof("remove") - 1);
|
||||
pkey->remove_s += 4;
|
||||
memcpy(pkey->remove_s, "remove", 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;
|
||||
memcpy(pkey->remove_s, name, 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;
|
||||
memcpy(pkey->remove_s, blob, 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_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;
|
||||
_libssh2_htonu32(pkey->listFetch_s, sizeof("list") - 1);
|
||||
pkey->listFetch_s += 4;
|
||||
|
||||
68
src/scp.c
68
src/scp.c
@@ -122,9 +122,9 @@
|
||||
until then it is kept static and in this source file.
|
||||
*/
|
||||
|
||||
static unsigned
|
||||
static size_t
|
||||
shell_quotearg(const char *path, unsigned char *buf,
|
||||
unsigned bufsize)
|
||||
size_t bufsize)
|
||||
{
|
||||
const char *src;
|
||||
unsigned char *dst, *endp;
|
||||
@@ -270,7 +270,7 @@ shell_quotearg(const char *path, unsigned char *buf,
|
||||
static LIBSSH2_CHANNEL *
|
||||
scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
|
||||
{
|
||||
int cmd_len;
|
||||
size_t cmd_len;
|
||||
int rc;
|
||||
int tmp_err_code;
|
||||
const char *tmp_err_msg;
|
||||
@@ -364,8 +364,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent1) {
|
||||
rc = _libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending initial wakeup");
|
||||
@@ -388,10 +388,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
|
||||
unsigned char *s, *p;
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent2) {
|
||||
rc = _libssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *) session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len, 1);
|
||||
rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *) session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len,
|
||||
1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for SCP response");
|
||||
@@ -550,8 +551,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent3) {
|
||||
rc = _libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting to send SCP ACK");
|
||||
@@ -587,10 +588,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
|
||||
char *s, *p, *e = NULL;
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent5) {
|
||||
rc = _libssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *) session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len, 1);
|
||||
rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *) session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len,
|
||||
1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for SCP response");
|
||||
@@ -714,8 +716,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent6) {
|
||||
rc = _libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending SCP ACK");
|
||||
@@ -833,7 +835,7 @@ static LIBSSH2_CHANNEL *
|
||||
scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
libssh2_int64_t size, time_t mtime, time_t atime)
|
||||
{
|
||||
int cmd_len;
|
||||
size_t cmd_len;
|
||||
int rc;
|
||||
int tmp_err_code;
|
||||
const char *tmp_err_msg;
|
||||
@@ -923,8 +925,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent1) {
|
||||
/* Wait for ACK */
|
||||
rc = _libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *) session->scpSend_response, 1);
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *) session->scpSend_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response from remote");
|
||||
@@ -958,9 +960,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
/* Send mtime and atime to be used for file */
|
||||
if(mtime || atime) {
|
||||
if(session->scpSend_state == libssh2_NB_state_sent2) {
|
||||
rc = _libssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
rc = (int)_libssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending time data for SCP file");
|
||||
@@ -977,8 +979,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent3) {
|
||||
/* Wait for ACK */
|
||||
rc = _libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *) session->scpSend_response, 1);
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *) session->scpSend_response,
|
||||
1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response");
|
||||
@@ -1026,9 +1029,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent5) {
|
||||
rc = _libssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
rc = (int)_libssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block send core file data for SCP file");
|
||||
@@ -1045,8 +1048,9 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent6) {
|
||||
/* Wait for ACK */
|
||||
rc = _libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *) session->scpSend_response, 1);
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *) session->scpSend_response,
|
||||
1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response");
|
||||
@@ -1074,8 +1078,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||
}
|
||||
|
||||
/* Read the remote error message */
|
||||
rc = _libssh2_channel_read(session->scpSend_channel, 0,
|
||||
err_msg, err_len);
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
err_msg, err_len);
|
||||
if(rc > 0) {
|
||||
err_msg[err_len] = 0;
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP,
|
||||
|
||||
@@ -330,6 +330,8 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DISABLED_NONBLOCKING
|
||||
(void)sockfd;
|
||||
(void)nonblock;
|
||||
return 0; /* returns success */
|
||||
#undef SETBLOCK
|
||||
#define SETBLOCK 6
|
||||
@@ -409,6 +411,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DISABLED_NONBLOCKING
|
||||
(void)sockfd;
|
||||
return 1; /* returns blocking */
|
||||
#undef GETBLOCK
|
||||
#define GETBLOCK 7
|
||||
@@ -651,7 +654,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
|
||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||
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
|
||||
{
|
||||
@@ -662,7 +665,11 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
|
||||
struct timeval tv;
|
||||
|
||||
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;
|
||||
#endif
|
||||
|
||||
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND) {
|
||||
FD_ZERO(&rfd);
|
||||
@@ -676,7 +683,7 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time)
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
@@ -1538,7 +1545,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
switch(fds[i].type) {
|
||||
case LIBSSH2_POLLFD_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;
|
||||
break;
|
||||
|
||||
@@ -1705,7 +1712,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
struct timeval tv_begin, tv_end;
|
||||
|
||||
_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);
|
||||
timeout_remaining -= (tv_end.tv_sec - tv_begin.tv_sec) * 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,
|
||||
* 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;
|
||||
#endif /* HAVE_GETTIMEOFDAY */
|
||||
|
||||
@@ -1768,7 +1775,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
|
||||
struct timeval tv_begin, tv_end;
|
||||
|
||||
_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);
|
||||
|
||||
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,
|
||||
* 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;
|
||||
#endif
|
||||
|
||||
|
||||
58
src/sftp.c
58
src/sftp.c
@@ -649,24 +649,24 @@ sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs)
|
||||
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) {
|
||||
_libssh2_store_u64(&s, attrs->filesize);
|
||||
}
|
||||
|
||||
if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
|
||||
_libssh2_store_u32(&s, attrs->uid);
|
||||
_libssh2_store_u32(&s, attrs->gid);
|
||||
_libssh2_store_u32(&s, (uint32_t)attrs->uid);
|
||||
_libssh2_store_u32(&s, (uint32_t)attrs->gid);
|
||||
}
|
||||
|
||||
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) {
|
||||
_libssh2_store_u32(&s, attrs->atime);
|
||||
_libssh2_store_u32(&s, attrs->mtime);
|
||||
_libssh2_store_u32(&s, (uint32_t)attrs->atime);
|
||||
_libssh2_store_u32(&s, (uint32_t)attrs->mtime);
|
||||
}
|
||||
|
||||
return (s - p);
|
||||
@@ -1118,9 +1118,9 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
|
||||
if(sftp->open_state == libssh2_NB_state_idle) {
|
||||
/* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) +
|
||||
flags(4) */
|
||||
sftp->open_packet_len = filename_len + 13 +
|
||||
sftp->open_packet_len = (uint32_t)(filename_len + 13 +
|
||||
(open_file? (4 +
|
||||
sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0);
|
||||
sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0));
|
||||
|
||||
/* surprise! this starts out with nothing sent */
|
||||
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) {
|
||||
size_t data_len;
|
||||
size_t data_len = 0;
|
||||
unsigned char *data;
|
||||
static const unsigned char fopen_responses[2] =
|
||||
{ SSH_FXP_HANDLE, SSH_FXP_STATUS };
|
||||
@@ -1453,8 +1453,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
||||
allows, expand it! */
|
||||
|
||||
rc = _libssh2_channel_receive_window_adjust(sftp->channel,
|
||||
max_read_ahead*8,
|
||||
1, NULL);
|
||||
(uint32_t)(max_read_ahead * 8),
|
||||
1, NULL);
|
||||
/* if this returns EAGAIN, we will get back to this function
|
||||
at next call */
|
||||
assert(rc != LIBSSH2_ERROR_EAGAIN || !filep->data_left);
|
||||
@@ -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) +
|
||||
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 size = count;
|
||||
uint32_t size = (uint32_t)count;
|
||||
if(size < buffer_size)
|
||||
size = buffer_size;
|
||||
size = (uint32_t)buffer_size;
|
||||
if(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
|
||||
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 */
|
||||
filep->data = data;
|
||||
@@ -1755,7 +1755,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
|
||||
size_t data_len = 0;
|
||||
uint32_t num_names;
|
||||
/* 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;
|
||||
static const unsigned char read_responses[2] = {
|
||||
SSH_FXP_NAME, SSH_FXP_STATUS };
|
||||
@@ -2057,12 +2057,12 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
|
||||
while(count) {
|
||||
/* TODO: Possibly this should have some logic to prevent a very
|
||||
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;
|
||||
|
||||
/* 25 = packet_len(4) + packet_type(1) + request_id(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 +
|
||||
sizeof(struct sftp_pipeline_chunk));
|
||||
@@ -2245,7 +2245,7 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
|
||||
LIBSSH2_SESSION *session = channel->session;
|
||||
/* 34 = packet_len(4) + packet_type(1) + request_id(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;
|
||||
unsigned char *packet, *s, *data = NULL;
|
||||
ssize_t rc;
|
||||
@@ -2353,8 +2353,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
|
||||
LIBSSH2_SESSION *session = channel->session;
|
||||
size_t data_len = 0;
|
||||
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) */
|
||||
uint32_t packet_len =
|
||||
handle->handle_len + 13 + (setstat ? sftp_attrsize(attrs->flags) : 0);
|
||||
uint32_t packet_len = (uint32_t)(handle->handle_len + 13 +
|
||||
(setstat ? sftp_attrsize(attrs->flags) : 0));
|
||||
unsigned char *s, *data = NULL;
|
||||
static const unsigned char fstat_responses[2] =
|
||||
{ SSH_FXP_ATTRS, SSH_FXP_STATUS };
|
||||
@@ -2578,7 +2578,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
|
||||
LIBSSH2_SESSION *session = channel->session;
|
||||
size_t data_len = 0;
|
||||
/* 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;
|
||||
int rc = 0;
|
||||
|
||||
@@ -2709,7 +2709,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
|
||||
size_t data_len = 0;
|
||||
int retcode;
|
||||
/* 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;
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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)
|
||||
+ handle_len (4) */
|
||||
/* 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;
|
||||
ssize_t rc;
|
||||
unsigned int flag;
|
||||
@@ -3252,7 +3252,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
|
||||
"packet");
|
||||
}
|
||||
|
||||
_libssh2_store_u32(&s, packet_len - 4);
|
||||
_libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
|
||||
*(s++) = SSH_FXP_MKDIR;
|
||||
sftp->mkdir_request_id = sftp->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");
|
||||
}
|
||||
|
||||
_libssh2_store_u32(&s, packet_len - 4);
|
||||
_libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
|
||||
*(s++) = SSH_FXP_RMDIR;
|
||||
sftp->rmdir_request_id = sftp->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");
|
||||
}
|
||||
|
||||
_libssh2_store_u32(&s, packet_len - 4);
|
||||
_libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
|
||||
|
||||
switch(stat_type) {
|
||||
case LIBSSH2_SFTP_SETSTAT:
|
||||
@@ -3612,7 +3612,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
|
||||
LIBSSH2_SFTP_REALPATH) ? "realpath" : "symlink",
|
||||
path));
|
||||
|
||||
_libssh2_store_u32(&s, packet_len - 4);
|
||||
_libssh2_store_u32(&s, (uint32_t)(packet_len - 4));
|
||||
|
||||
switch(link_type) {
|
||||
case LIBSSH2_SFTP_REALPATH:
|
||||
|
||||
@@ -864,7 +864,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
|
||||
/* store packet_length, which is the size of the whole packet except
|
||||
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 */
|
||||
p->outbuf[4] = (unsigned char)padding_length;
|
||||
|
||||
|
||||
@@ -611,7 +611,8 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
|
||||
}
|
||||
|
||||
if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len,
|
||||
(char *) sp1, sp2 - sp1)) {
|
||||
(const char *) sp1,
|
||||
(unsigned int)(sp2 - sp1))) {
|
||||
LIBSSH2_FREE(session, pubkey);
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"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,
|
||||
(char *) sp1, sp2 - sp1)) {
|
||||
(const char *) sp1,
|
||||
(unsigned int)(sp2 - sp1))) {
|
||||
LIBSSH2_FREE(session, pubkey);
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"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;
|
||||
|
||||
_libssh2_store_u32(&x, *sig_len - 4);
|
||||
_libssh2_store_u32(&x, (uint32_t)(*sig_len - 4));
|
||||
}
|
||||
else {
|
||||
_libssh2_debug((session,
|
||||
@@ -1144,8 +1146,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
|
||||
session->userauth_host_packet + session->userauth_host_packet_len;
|
||||
|
||||
_libssh2_store_u32(&session->userauth_host_s,
|
||||
4 + session->userauth_host_method_len +
|
||||
4 + sig_len);
|
||||
(uint32_t)(4 + session->userauth_host_method_len +
|
||||
4 + sig_len));
|
||||
_libssh2_store_str(&session->userauth_host_s,
|
||||
(const char *)session->userauth_host_method,
|
||||
session->userauth_host_method_len);
|
||||
@@ -1709,8 +1711,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
|
||||
"sk-ssh-ed25519@openssh.com",
|
||||
session->userauth_pblc_method_len) == 0) {
|
||||
_libssh2_store_u32(&s,
|
||||
4 + session->userauth_pblc_method_len +
|
||||
sig_len);
|
||||
(uint32_t)(4 + session->userauth_pblc_method_len +
|
||||
sig_len));
|
||||
_libssh2_store_str(&s, (const char *)session->userauth_pblc_method,
|
||||
session->userauth_pblc_method_len);
|
||||
memcpy(s, sig, sig_len);
|
||||
@@ -1718,8 +1720,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
|
||||
}
|
||||
else {
|
||||
_libssh2_store_u32(&s,
|
||||
4 + session->userauth_pblc_method_len + 4 +
|
||||
sig_len);
|
||||
(uint32_t)(4 + session->userauth_pblc_method_len +
|
||||
4 + sig_len));
|
||||
_libssh2_store_str(&s, (const char *)session->userauth_pblc_method,
|
||||
session->userauth_pblc_method_len);
|
||||
_libssh2_store_str(&s, (const char *)sig, sig_len);
|
||||
|
||||
11
src/wincng.c
11
src/wincng.c
@@ -668,7 +668,7 @@ _libssh2_wincng_key_sha_verify(_libssh2_wincng_key_ctx *ctx,
|
||||
memcpy(data, sig, datalen);
|
||||
|
||||
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(data, datalen);
|
||||
@@ -2120,13 +2120,13 @@ _libssh2_wincng_bignum_rand(_libssh2_bn *rnd, int bits, int top, int bottom)
|
||||
bits = 8;
|
||||
|
||||
/* 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 */
|
||||
if(top == 0)
|
||||
bignum[0] |= (1 << (bits - 1));
|
||||
bignum[0] |= (unsigned char)(1 << (bits - 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 */
|
||||
if(bottom)
|
||||
@@ -2551,7 +2551,8 @@ _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret,
|
||||
unsigned char *start, *end;
|
||||
BCRYPT_DH_KEY_BLOB *public_blob = NULL;
|
||||
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
|
||||
|
||||
50
src/wincng.h
50
src/wincng.h
@@ -148,10 +148,11 @@ typedef struct __libssh2_wincng_hash_ctx {
|
||||
|
||||
#define libssh2_sha1_ctx _libssh2_wincng_hash_ctx
|
||||
#define libssh2_sha1_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \
|
||||
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \
|
||||
SHA_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#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) \
|
||||
_libssh2_wincng_hash_final(&ctx, hash)
|
||||
#define libssh2_sha1(data, datalen, hash) \
|
||||
@@ -160,32 +161,37 @@ typedef struct __libssh2_wincng_hash_ctx {
|
||||
|
||||
#define libssh2_sha256_ctx _libssh2_wincng_hash_ctx
|
||||
#define libssh2_sha256_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \
|
||||
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \
|
||||
SHA256_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#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) \
|
||||
_libssh2_wincng_hash_final(&ctx, hash)
|
||||
#define libssh2_sha256(data, datalen, hash) \
|
||||
_libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA256, \
|
||||
hash, SHA256_DIGEST_LENGTH)
|
||||
|
||||
#define libssh2_sha384_ctx _libssh2_wincng_hash_ctx
|
||||
#define libssh2_sha384_init(ctx) \
|
||||
(_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) \
|
||||
_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) \
|
||||
_libssh2_wincng_hash_final(&ctx, hash)
|
||||
_libssh2_wincng_hash_final(&ctx, hash)
|
||||
#define libssh2_sha384(data, datalen, hash) \
|
||||
_libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \
|
||||
hash, SHA384_DIGEST_LENGTH)
|
||||
_libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \
|
||||
hash, SHA384_DIGEST_LENGTH)
|
||||
|
||||
#define libssh2_sha512_ctx _libssh2_wincng_hash_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)
|
||||
#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) \
|
||||
_libssh2_wincng_hash_final(&ctx, hash)
|
||||
#define libssh2_sha512(data, datalen, hash) \
|
||||
@@ -194,10 +200,11 @@ _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA384, \
|
||||
|
||||
#define libssh2_md5_ctx _libssh2_wincng_hash_ctx
|
||||
#define libssh2_md5_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \
|
||||
(_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \
|
||||
MD5_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#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) \
|
||||
_libssh2_wincng_hash_final(&ctx, 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_sha1_init(ctx, key, keylen) \
|
||||
_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) \
|
||||
_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)
|
||||
/* not implemented */
|
||||
#define libssh2_hmac_sha256_init(ctx, key, keylen) \
|
||||
_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) \
|
||||
_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) \
|
||||
_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) \
|
||||
_libssh2_wincng_hmac_final(&ctx, hash)
|
||||
#define libssh2_hmac_cleanup(ctx) \
|
||||
@@ -396,7 +408,7 @@ _libssh2_bn *_libssh2_wincng_bignum_init(void);
|
||||
#define _libssh2_bn_set_word(bn, word) \
|
||||
_libssh2_wincng_bignum_set_word(bn, word)
|
||||
#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) \
|
||||
_libssh2_wincng_bignum_to_bin(bn, bin)
|
||||
#define _libssh2_bn_bytes(bn) bn->length
|
||||
|
||||
Reference in New Issue
Block a user