1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-10 06:23:02 +03:00

src: fix checksrc warnings

Use checksrc.pl from the curl project, with (for now)
suppressed long line warnings and indentation set to
4 spaces. Fixes are whitespace for the most part.

Warning count went down from 2704 to 12.

Also fix codespell typos, two non-ANSI C89 comments
and a stray tab in include/libssh2.h.

Ref: https://github.com/libssh2/libssh2/pull/235
This commit is contained in:
Viktor Szakats
2018-03-12 11:08:21 +00:00
parent fad6e5bb02
commit e54ef175d4
30 changed files with 2788 additions and 2612 deletions

View File

@@ -621,7 +621,8 @@ agent_list_identities(LIBSSH2_AGENT *agent)
} }
static void static void
agent_free_identities(LIBSSH2_AGENT *agent) { agent_free_identities(LIBSSH2_AGENT *agent)
{
struct agent_publickey *node; struct agent_publickey *node;
struct agent_publickey *next; struct agent_publickey *next;
@@ -707,7 +708,7 @@ LIBSSH2_API int
libssh2_agent_list_identities(LIBSSH2_AGENT *agent) libssh2_agent_list_identities(LIBSSH2_AGENT *agent)
{ {
memset(&agent->transctx, 0, sizeof agent->transctx); memset(&agent->transctx, 0, sizeof agent->transctx);
/* Abondon the last fetched identities */ /* Abandon the last fetched identities */
agent_free_identities(agent); agent_free_identities(agent);
return agent_list_identities(agent); return agent_list_identities(agent);
} }
@@ -801,7 +802,8 @@ libssh2_agent_disconnect(LIBSSH2_AGENT *agent)
* collection of public keys. * collection of public keys.
*/ */
LIBSSH2_API void LIBSSH2_API void
libssh2_agent_free(LIBSSH2_AGENT *agent) { libssh2_agent_free(LIBSSH2_AGENT *agent)
{
/* Allow connection freeing when the socket has lost its connection */ /* Allow connection freeing when the socket has lost its connection */
if(agent->fd != LIBSSH2_INVALID_SOCKET) { if(agent->fd != LIBSSH2_INVALID_SOCKET) {
libssh2_agent_disconnect(agent); libssh2_agent_disconnect(agent);

View File

@@ -234,7 +234,8 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL; return NULL;
} else if (rc) { }
else if(rc) {
goto channel_error; goto channel_error;
} }
@@ -518,7 +519,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL; return NULL;
} else if (rc) { }
else if(rc) {
_libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown"); _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown");
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_state = libssh2_NB_state_idle;
return NULL; return NULL;
@@ -645,7 +647,8 @@ int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener)
_libssh2_store_u32(&s, listener->port); _libssh2_store_u32(&s, listener->port);
listener->chanFwdCncl_state = libssh2_NB_state_created; listener->chanFwdCncl_state = libssh2_NB_state_created;
} else { }
else {
packet = listener->chanFwdCncl_data; packet = listener->chanFwdCncl_data;
} }
@@ -827,7 +830,8 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
_libssh2_error(session, rc, _libssh2_error(session, rc,
"Would block sending setenv request"); "Would block sending setenv request");
return rc; return rc;
} else if (rc) { }
else if(rc) {
LIBSSH2_FREE(session, channel->setenv_packet); LIBSSH2_FREE(session, channel->setenv_packet);
channel->setenv_packet = NULL; channel->setenv_packet = NULL;
channel->setenv_state = libssh2_NB_state_idle; channel->setenv_state = libssh2_NB_state_idle;
@@ -952,7 +956,8 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
_libssh2_error(session, rc, _libssh2_error(session, rc,
"Would block sending pty request"); "Would block sending pty request");
return rc; return rc;
} else if (rc) { }
else if(rc) {
channel->reqPTY_state = libssh2_NB_state_idle; channel->reqPTY_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send pty-request packet"); "Unable to send pty-request packet");
@@ -971,7 +976,8 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
&channel->reqPTY_packet_requirev_state); &channel->reqPTY_packet_requirev_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
channel->reqPTY_state = libssh2_NB_state_idle; channel->reqPTY_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_PROTO, return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Failed to require the PTY package"); "Failed to require the PTY package");
@@ -1056,7 +1062,8 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
_libssh2_error(session, rc, _libssh2_error(session, rc,
"Would block sending window-change request"); "Would block sending window-change request");
return rc; return rc;
} else if (rc) { }
else if(rc) {
channel->reqPTY_state = libssh2_NB_state_idle; channel->reqPTY_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send window-change packet"); "Unable to send window-change packet");
@@ -1144,7 +1151,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
_libssh2_store_u32(&s, cookie_len); _libssh2_store_u32(&s, cookie_len);
if(auth_cookie) { if(auth_cookie) {
memcpy(s, auth_cookie, cookie_len); memcpy(s, auth_cookie, cookie_len);
} else { }
else {
int i; int i;
/* note: the extra +1 below is necessary since the sprintf() /* note: the extra +1 below is necessary since the sprintf()
loop will always write 3 bytes so the last one will write loop will always write 3 bytes so the last one will write
@@ -1197,7 +1205,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
&channel->reqX11_packet_requirev_state); &channel->reqX11_packet_requirev_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
channel->reqX11_state = libssh2_NB_state_idle; channel->reqX11_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"waiting for x11-req response packet"); "waiting for x11-req response packet");
@@ -1324,7 +1333,8 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
&channel->process_packet_requirev_state); &channel->process_packet_requirev_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
channel->process_state = libssh2_NB_state_end; channel->process_state = libssh2_NB_state_end;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Failed waiting for channel success"); "Failed waiting for channel success");
@@ -1526,7 +1536,8 @@ libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel,
} }
if(exitsignal_len) if(exitsignal_len)
*exitsignal_len = namelen; *exitsignal_len = namelen;
} else { }
else {
if(exitsignal) if(exitsignal)
*exitsignal = NULL; *exitsignal = NULL;
if(exitsignal_len) if(exitsignal_len)
@@ -1979,8 +1990,7 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id)
&& (read_packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA) && (read_packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA)
&& (channel->local.id == read_local_id) && (channel->local.id == read_local_id)
&& (channel->remote.extended_data_ignore_mode && (channel->remote.extended_data_ignore_mode
== LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE))) == LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE))) {
{
return (read_packet->data_len - read_packet->data_head); return (read_packet->data_len - read_packet->data_head);
} }
read_packet = _libssh2_list_next(&read_packet->node); read_packet = _libssh2_list_next(&read_packet->node);
@@ -2308,7 +2318,8 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel)
} }
if(!channel->local.eof) { if(!channel->local.eof) {
if ((rc = channel_send_eof(channel))) { rc = channel_send_eof(channel);
if(rc) {
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} }
@@ -2338,14 +2349,16 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel)
"Would block sending close-channel"); "Would block sending close-channel");
return rc; return rc;
} else if (rc) { }
else if(rc) {
_libssh2_error(session, rc, _libssh2_error(session, rc,
"Unable to send close-channel request, " "Unable to send close-channel request, "
"but closing anyway"); "but closing anyway");
/* skip waiting for the response and fall through to /* skip waiting for the response and fall through to
LIBSSH2_CHANNEL_CLOSE below */ LIBSSH2_CHANNEL_CLOSE below */
} else }
else
channel->close_state = libssh2_NB_state_sent; channel->close_state = libssh2_NB_state_sent;
} }

View File

@@ -154,7 +154,8 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compr,
if(compr) { if(compr) {
/* deflate */ /* deflate */
status = deflateInit(strm, Z_DEFAULT_COMPRESSION); status = deflateInit(strm, Z_DEFAULT_COMPRESSION);
} else { }
else {
/* inflate */ /* inflate */
status = inflateInit(strm); status = inflateInit(strm);
} }
@@ -259,10 +260,12 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session,
if(strm->avail_out > 0) if(strm->avail_out > 0)
/* status is OK and the output buffer has not been exhausted so we're done */ /* status is OK and the output buffer has not been exhausted so we're done */
break; break;
} else if (status == Z_BUF_ERROR) { }
else if(status == Z_BUF_ERROR) {
/* the input data has been exhausted so we are done */ /* the input data has been exhausted so we are done */
break; break;
} else { }
else {
/* error state */ /* error state */
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);
_libssh2_debug(session, LIBSSH2_TRACE_TRANS, _libssh2_debug(session, LIBSSH2_TRACE_TRANS,

View File

@@ -526,11 +526,14 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
if(strncmp((char *) s, "ecdsa-sha2-nistp256", 19) == 0) { if(strncmp((char *) s, "ecdsa-sha2-nistp256", 19) == 0) {
type = LIBSSH2_EC_CURVE_NISTP256; type = LIBSSH2_EC_CURVE_NISTP256;
} else if(strncmp((char*) s, "ecdsa-sha2-nistp384", 19) == 0 ) { }
else if(strncmp((char *) s, "ecdsa-sha2-nistp384", 19) == 0) {
type = LIBSSH2_EC_CURVE_NISTP384; type = LIBSSH2_EC_CURVE_NISTP384;
} else if(strncmp((char*) s, "ecdsa-sha2-nistp521", 19) == 0 ) { }
else if(strncmp((char *) s, "ecdsa-sha2-nistp521", 19) == 0) {
type = LIBSSH2_EC_CURVE_NISTP521; type = LIBSSH2_EC_CURVE_NISTP521;
} else { }
else {
return -1; return -1;
} }
s += 19; s += 19;
@@ -544,9 +547,11 @@ hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION * session,
if(type == LIBSSH2_EC_CURVE_NISTP256 && strncmp((char *)s, "nistp256", 8) != 0) { if(type == LIBSSH2_EC_CURVE_NISTP256 && strncmp((char *)s, "nistp256", 8) != 0) {
return -1; return -1;
} else if ( type == LIBSSH2_EC_CURVE_NISTP384 && strncmp((char*)s, "nistp384", 8) != 0) { }
else if(type == LIBSSH2_EC_CURVE_NISTP384 && strncmp((char *)s, "nistp384", 8) != 0) {
return -1; return -1;
} else if ( type == LIBSSH2_EC_CURVE_NISTP521 && strncmp((char*)s, "nistp521", 8) != 0) { }
else if(type == LIBSSH2_EC_CURVE_NISTP521 && strncmp((char *)s, "nistp521", 8) != 0) {
return -1; return -1;
} }
@@ -699,11 +704,14 @@ hostkey_method_ssh_ecdsa_signv(LIBSSH2_SESSION * session,
if(type == LIBSSH2_EC_CURVE_NISTP256) { if(type == LIBSSH2_EC_CURVE_NISTP256) {
LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(256); LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(256);
}else if ( type == LIBSSH2_EC_CURVE_NISTP384 ) { }
else if(type == LIBSSH2_EC_CURVE_NISTP384) {
LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(384); LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(384);
}else if ( type == LIBSSH2_EC_CURVE_NISTP521 ){ }
else if(type == LIBSSH2_EC_CURVE_NISTP521) {
LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(512); LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(512);
}else{ }
else {
return -1; return -1;
} }

View File

@@ -90,7 +90,8 @@ libssh2_keepalive_send (LIBSSH2_SESSION *session,
session->keepalive_last_sent = now; session->keepalive_last_sent = now;
if(seconds_to_next) if(seconds_to_next)
*seconds_to_next = session->keepalive_interval; *seconds_to_next = session->keepalive_interval;
} else if (seconds_to_next) { }
else if(seconds_to_next) {
*seconds_to_next = (int) (session->keepalive_last_sent - now) *seconds_to_next = (int) (session->keepalive_last_sent - now)
+ session->keepalive_interval; + session->keepalive_interval;
} }

113
src/kex.c
View File

@@ -60,7 +60,8 @@
SHA_DIGEST_LENGTH); \ SHA_DIGEST_LENGTH); \
if(len > 0) { \ if(len > 0) { \
libssh2_sha1_update(hash, value, len); \ libssh2_sha1_update(hash, value, len); \
} else { \ } \
else { \
libssh2_sha1_update(hash, (version), 1); \ libssh2_sha1_update(hash, (version), 1); \
libssh2_sha1_update(hash, session->session_id, \ libssh2_sha1_update(hash, session->session_id, \
session->session_id_len); \ session->session_id_len); \
@@ -101,7 +102,8 @@
SHA##digest_type##_DIGEST_LENGTH); \ SHA##digest_type##_DIGEST_LENGTH); \
if(len > 0) { \ if(len > 0) { \
libssh2_sha##digest_type##_update(hash, value, len); \ libssh2_sha##digest_type##_update(hash, value, len); \
} else { \ } \
else { \
libssh2_sha##digest_type##_update(hash, (version), 1); \ libssh2_sha##digest_type##_update(hash, (version), 1); \
libssh2_sha##digest_type##_update(hash, session->session_id, \ libssh2_sha##digest_type##_update(hash, session->session_id, \
session->session_id_len); \ session->session_id_len); \
@@ -173,7 +175,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if(_libssh2_bn_bits(exchange_state->e) % 8) { if(_libssh2_bn_bits(exchange_state->e) % 8) {
_libssh2_bn_to_bin(exchange_state->e, _libssh2_bn_to_bin(exchange_state->e,
exchange_state->e_packet + 5); exchange_state->e_packet + 5);
} else { }
else {
exchange_state->e_packet[5] = 0; exchange_state->e_packet[5] = 0;
_libssh2_bn_to_bin(exchange_state->e, _libssh2_bn_to_bin(exchange_state->e,
exchange_state->e_packet + 6); exchange_state->e_packet + 6);
@@ -190,7 +193,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
NULL, 0); NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to send KEX init message"); "Unable to send KEX init message");
goto clean_exit; goto clean_exit;
@@ -211,7 +215,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
_libssh2_packet_burn(session, &exchange_state->burn_state); _libssh2_packet_burn(session, &exchange_state->burn_state);
if(burn_type == LIBSSH2_ERROR_EAGAIN) { if(burn_type == LIBSSH2_ERROR_EAGAIN) {
return burn_type; return burn_type;
} else if (burn_type <= 0) { }
else if(burn_type <= 0) {
/* Failed to receive a packet */ /* Failed to receive a packet */
ret = burn_type; ret = burn_type;
goto clean_exit; goto clean_exit;
@@ -385,7 +390,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
exchange_state->k_value_len - 4); 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);
} else { }
else {
exchange_state->k_value[4] = 0; exchange_state->k_value[4] = 0;
_libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 5); _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 5);
} }
@@ -401,7 +407,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
libssh2_sha1_update(exchange_hash_ctx, libssh2_sha1_update(exchange_hash_ctx,
session->local.banner, session->local.banner,
strlen((char *) session->local.banner) - 2); strlen((char *) session->local.banner) - 2);
} else { }
else {
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1);
libssh2_sha1_update(exchange_hash_ctx, libssh2_sha1_update(exchange_hash_ctx,
@@ -505,7 +512,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
rc = _libssh2_transport_send(session, &exchange_state->c, 1, NULL, 0); rc = _libssh2_transport_send(session, &exchange_state->c, 1, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message"); ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message");
goto clean_exit; goto clean_exit;
} }
@@ -520,7 +528,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
&exchange_state->req_state); &exchange_state->req_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS");
goto clean_exit; goto clean_exit;
} }
@@ -827,7 +836,8 @@ static int diffie_hellman_sha256(LIBSSH2_SESSION *session,
if(_libssh2_bn_bits(exchange_state->e) % 8) { if(_libssh2_bn_bits(exchange_state->e) % 8) {
_libssh2_bn_to_bin(exchange_state->e, _libssh2_bn_to_bin(exchange_state->e,
exchange_state->e_packet + 5); exchange_state->e_packet + 5);
} else { }
else {
exchange_state->e_packet[5] = 0; exchange_state->e_packet[5] = 0;
_libssh2_bn_to_bin(exchange_state->e, _libssh2_bn_to_bin(exchange_state->e,
exchange_state->e_packet + 6); exchange_state->e_packet + 6);
@@ -844,7 +854,8 @@ static int diffie_hellman_sha256(LIBSSH2_SESSION *session,
NULL, 0); NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to send KEX init message"); "Unable to send KEX init message");
goto clean_exit; goto clean_exit;
@@ -865,7 +876,8 @@ static int diffie_hellman_sha256(LIBSSH2_SESSION *session,
_libssh2_packet_burn(session, &exchange_state->burn_state); _libssh2_packet_burn(session, &exchange_state->burn_state);
if(burn_type == LIBSSH2_ERROR_EAGAIN) { if(burn_type == LIBSSH2_ERROR_EAGAIN) {
return burn_type; return burn_type;
} else if (burn_type <= 0) { }
else if(burn_type <= 0) {
/* Failed to receive a packet */ /* Failed to receive a packet */
ret = burn_type; ret = burn_type;
goto clean_exit; goto clean_exit;
@@ -1038,7 +1050,8 @@ static int diffie_hellman_sha256(LIBSSH2_SESSION *session,
exchange_state->k_value_len - 4); 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);
} else { }
else {
exchange_state->k_value[4] = 0; exchange_state->k_value[4] = 0;
_libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 5); _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 5);
} }
@@ -1054,7 +1067,8 @@ static int diffie_hellman_sha256(LIBSSH2_SESSION *session,
libssh2_sha256_update(exchange_hash_ctx, libssh2_sha256_update(exchange_hash_ctx,
session->local.banner, session->local.banner,
strlen((char *) session->local.banner) - 2); strlen((char *) session->local.banner) - 2);
} else { }
else {
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1);
libssh2_sha256_update(exchange_hash_ctx, libssh2_sha256_update(exchange_hash_ctx,
@@ -1160,7 +1174,8 @@ static int diffie_hellman_sha256(LIBSSH2_SESSION *session,
rc = _libssh2_transport_send(session, &exchange_state->c, 1, NULL, 0); rc = _libssh2_transport_send(session, &exchange_state->c, 1, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message"); ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message");
goto clean_exit; goto clean_exit;
} }
@@ -1175,7 +1190,8 @@ static int diffie_hellman_sha256(LIBSSH2_SESSION *session,
&exchange_state->req_state); &exchange_state->req_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS");
goto clean_exit; goto clean_exit;
} }
@@ -1599,7 +1615,8 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
key_state->request_len, NULL, 0); key_state->request_len, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to send Group Exchange Request"); "Unable to send Group Exchange Request");
goto dh_gex_clean_exit; goto dh_gex_clean_exit;
@@ -1614,7 +1631,8 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
0, NULL, 0, &key_state->req_state); 0, NULL, 0, &key_state->req_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Timeout waiting for GEX_GROUP reply"); "Timeout waiting for GEX_GROUP reply");
goto dh_gex_clean_exit; goto dh_gex_clean_exit;
@@ -1699,7 +1717,8 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
key_state->request_len, NULL, 0); key_state->request_len, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to send Group Exchange Request SHA256"); "Unable to send Group Exchange Request SHA256");
goto dh_gex_clean_exit; goto dh_gex_clean_exit;
@@ -1714,7 +1733,8 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
0, NULL, 0, &key_state->req_state); 0, NULL, 0, &key_state->req_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Timeout waiting for GEX_GROUP reply SHA256"); "Timeout waiting for GEX_GROUP reply SHA256");
goto dh_gex_clean_exit; goto dh_gex_clean_exit;
@@ -1823,7 +1843,8 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type)
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
(char *) session->local.banner, \ (char *) session->local.banner, \
strlen((char *) session->local.banner) - 2); \ strlen((char *) session->local.banner) - 2); \
} else { \ } \
else { \
_libssh2_htonu32(exchange_state->h_sig_comp, \ _libssh2_htonu32(exchange_state->h_sig_comp, \
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); \ sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); \
libssh2_sha##digest_type##_update(ctx, \ libssh2_sha##digest_type##_update(ctx, \
@@ -1916,8 +1937,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
exchange_state->state = libssh2_NB_state_created; exchange_state->state = libssh2_NB_state_created;
} }
if ( exchange_state->state == libssh2_NB_state_created ) if(exchange_state->state == libssh2_NB_state_created) {
{
/* parse INIT reply data */ /* parse INIT reply data */
/* host key K_S */ /* host key K_S */
@@ -2068,7 +2088,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
exchange_state->k_value_len - 4); 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);
} else { }
else {
exchange_state->k_value[4] = 0; exchange_state->k_value[4] = 0;
_libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 5); _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 5);
} }
@@ -2102,7 +2123,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
rc = _libssh2_transport_send(session, &exchange_state->c, 1, NULL, 0); rc = _libssh2_transport_send(session, &exchange_state->c, 1, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message"); ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message");
goto clean_exit; goto clean_exit;
} }
@@ -2117,7 +2139,8 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
&exchange_state->req_state); &exchange_state->req_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS");
goto clean_exit; goto clean_exit;
} }
@@ -2383,8 +2406,7 @@ kex_method_ecdh_key_exchange
key_state->state = libssh2_NB_state_created; key_state->state = libssh2_NB_state_created;
} }
if ( key_state->state == libssh2_NB_state_created ) if(key_state->state == libssh2_NB_state_created) {
{
rc = kex_session_ecdh_curve_type(session->kex->name, &type); rc = kex_session_ecdh_curve_type(session->kex->name, &type);
if(rc != 0) { if(rc != 0) {
@@ -2396,8 +2418,7 @@ kex_method_ecdh_key_exchange
rc = _libssh2_ecdsa_create_key(&key_state->private_key, &key_state->public_key_oct, rc = _libssh2_ecdsa_create_key(&key_state->private_key, &key_state->public_key_oct,
&key_state->public_key_oct_len, type); &key_state->public_key_oct_len, type);
if ( rc != 0 ) if(rc != 0) {
{
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to create private key"); "Unable to create private key");
goto ecdh_clean_exit; goto ecdh_clean_exit;
@@ -2419,7 +2440,8 @@ kex_method_ecdh_key_exchange
key_state->request_len, NULL, 0); key_state->request_len, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to send ECDH_INIT"); "Unable to send ECDH_INIT");
goto ecdh_clean_exit; goto ecdh_clean_exit;
@@ -2434,7 +2456,8 @@ kex_method_ecdh_key_exchange
0, NULL, 0, &key_state->req_state); 0, NULL, 0, &key_state->req_state);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
ret = _libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Timeout waiting for ECDH_REPLY reply"); "Timeout waiting for ECDH_REPLY reply");
goto ecdh_clean_exit; goto ecdh_clean_exit;
@@ -2608,7 +2631,8 @@ kex_method_list(unsigned char *buf, size_t list_strlen,
buf += 4; \ buf += 4; \
memcpy((buf), (prefvar), (prefvarlen)); \ memcpy((buf), (prefvar), (prefvarlen)); \
buf += (prefvarlen); \ buf += (prefvarlen); \
} else { \ } \
else { \
buf += kex_method_list((buf), (prefvarlen), \ buf += kex_method_list((buf), (prefvarlen), \
(LIBSSH2_COMMON_METHOD**)(defaultvar)); \ (LIBSSH2_COMMON_METHOD**)(defaultvar)); \
} }
@@ -2736,7 +2760,8 @@ static int kexinit(LIBSSH2_SESSION * session)
#endif /* LIBSSH2DEBUG */ #endif /* LIBSSH2DEBUG */
session->kexinit_state = libssh2_NB_state_created; session->kexinit_state = libssh2_NB_state_created;
} else { }
else {
data = session->kexinit_data; data = session->kexinit_data;
data_len = session->kexinit_data_len; data_len = session->kexinit_data_len;
/* zap the variables to ensure there is NOT a double free later */ /* zap the variables to ensure there is NOT a double free later */
@@ -2772,7 +2797,7 @@ static int kexinit(LIBSSH2_SESSION * session)
/* kex_agree_instr /* kex_agree_instr
* Kex specific variant of strstr() * Kex specific variant of strstr()
* Needle must be preceed by BOL or ',', and followed by ',' or EOL * Needle must be precede by BOL or ',', and followed by ',' or EOL
*/ */
static unsigned char * static unsigned char *
kex_agree_instr(unsigned char *haystack, unsigned long haystack_len, kex_agree_instr(unsigned char *haystack, unsigned long haystack_len,
@@ -2921,7 +2946,8 @@ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex,
while(s && *s) { while(s && *s) {
unsigned char *q, *p = (unsigned char *) strchr((char *) s, ','); unsigned char *q, *p = (unsigned char *) strchr((char *) s, ',');
size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s)); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s));
if ((q = kex_agree_instr(kex, kex_len, s, method_len))) { q = kex_agree_instr(kex, kex_len, s, method_len);
if(q) {
const LIBSSH2_KEX_METHOD *method = (const LIBSSH2_KEX_METHOD *) const LIBSSH2_KEX_METHOD *method = (const LIBSSH2_KEX_METHOD *)
kex_get_method_by_name((char *) s, method_len, kex_get_method_by_name((char *) s, method_len,
(const LIBSSH2_COMMON_METHOD **) (const LIBSSH2_COMMON_METHOD **)
@@ -3314,7 +3340,8 @@ _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
if(retcode == LIBSSH2_ERROR_EAGAIN) { if(retcode == LIBSSH2_ERROR_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return retcode; return retcode;
} else if (retcode) { }
else if(retcode) {
session->local.kexinit = key_state->oldlocal; session->local.kexinit = key_state->oldlocal;
session->local.kexinit_len = key_state->oldlocal_len; session->local.kexinit_len = key_state->oldlocal_len;
key_state->state = libssh2_NB_state_idle; key_state->state = libssh2_NB_state_idle;
@@ -3360,7 +3387,8 @@ _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
key_state->state = libssh2_NB_state_sent2; key_state->state = libssh2_NB_state_sent2;
} }
} else { }
else {
key_state->state = libssh2_NB_state_sent2; key_state->state = libssh2_NB_state_sent2;
} }
@@ -3371,7 +3399,8 @@ _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
if(retcode == LIBSSH2_ERROR_EAGAIN) { if(retcode == LIBSSH2_ERROR_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return retcode; return retcode;
} else if (retcode) { }
else if(retcode) {
rc = _libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE, rc = _libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE,
"Unrecoverable error exchanging keys"); "Unrecoverable error exchanging keys");
} }
@@ -3482,10 +3511,12 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
/* Strip out unsupported method */ /* Strip out unsupported method */
if(p) { if(p) {
memcpy(s, p + 1, strlen(s) - method_len); memcpy(s, p + 1, strlen(s) - method_len);
} else { }
else {
if(s > newprefs) { if(s > newprefs) {
*(--s) = '\0'; *(--s) = '\0';
} else { }
else {
*s = '\0'; *s = '\0';
} }
} }

View File

@@ -149,7 +149,8 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
"No key type set"); "No key type set");
if(!(entry = LIBSSH2_CALLOC(hosts->session, sizeof(struct known_host)))) entry = LIBSSH2_CALLOC(hosts->session, sizeof(struct known_host));
if(!entry)
return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for known host " "Unable to allocate memory for known host "
"entry"); "entry");
@@ -450,9 +451,9 @@ knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
- if key_type is set to zero, ignore it an match always - if key_type is set to zero, ignore it an match always
- otherwise match when both key types are equal - otherwise match when both key types are equal
*/ */
if ( (host_key_type != LIBSSH2_KNOWNHOST_KEY_UNKNOWN ) && if(host_key_type != LIBSSH2_KNOWNHOST_KEY_UNKNOWN &&
( (host_key_type == 0) || (host_key_type == 0 ||
(host_key_type == known_key_type) ) ) { host_key_type == known_key_type)) {
/* host name and key type match, now compare the keys */ /* host name and key type match, now compare the keys */
if(!strcmp(key, node->key)) { if(!strcmp(key, node->key)) {
/* they match! */ /* they match! */

View File

@@ -72,7 +72,8 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
"(private-key(rsa(n%b)(e%b)(d%b)(q%b)(p%b)(u%b)))", "(private-key(rsa(n%b)(e%b)(d%b)(q%b)(p%b)(u%b)))",
nlen, ndata, elen, edata, dlen, ddata, plen, pdata, nlen, ndata, elen, edata, dlen, ddata, plen, pdata,
qlen, qdata, coefflen, coeffdata); qlen, qdata, coefflen, coeffdata);
} else { }
else {
rc = gcry_sexp_build(rsa, NULL, "(public-key(rsa(n%b)(e%b)))", rc = gcry_sexp_build(rsa, NULL, "(public-key(rsa(n%b)(e%b)))",
nlen, ndata, elen, edata); nlen, ndata, elen, edata);
} }
@@ -135,7 +136,8 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx,
(dsactx, NULL, (dsactx, NULL,
"(private-key(dsa(p%b)(q%b)(g%b)(y%b)(x%b)))", "(private-key(dsa(p%b)(q%b)(g%b)(y%b)(x%b)))",
p_len, p, q_len, q, g_len, g, y_len, y, x_len, x); p_len, p, q_len, q, g_len, g, y_len, y, x_len, x);
} else { }
else {
rc = gcry_sexp_build(dsactx, NULL, rc = gcry_sexp_build(dsactx, NULL,
"(public-key(dsa(p%b)(q%b)(g%b)(y%b)))", "(public-key(dsa(p%b)(q%b)(g%b)(y%b)))",
p_len, p, q_len, q, g_len, g, y_len, y); p_len, p, q_len, q, g_len, g, y_len, y);
@@ -583,7 +585,8 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
if(encrypt) { if(encrypt) {
ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen); ret = gcry_cipher_encrypt(*ctx, block, blklen, block, blklen);
} else { }
else {
ret = gcry_cipher_decrypt(*ctx, block, blklen, block, blklen); ret = gcry_cipher_decrypt(*ctx, block, blklen, block, blklen);
} }
return ret; return ret;

View File

@@ -102,8 +102,7 @@ _libssh2_mbedtls_cipher_crypt(_libssh2_cipher_ctx *ctx,
osize = blocklen + mbedtls_cipher_get_block_size(ctx); osize = blocklen + mbedtls_cipher_get_block_size(ctx);
output = (unsigned char *)mbedtls_calloc(osize, sizeof(char)); output = (unsigned char *)mbedtls_calloc(osize, sizeof(char));
if(output) if(output) {
{
ret = mbedtls_cipher_reset(ctx); ret = mbedtls_cipher_reset(ctx);
if(!ret) if(!ret)
@@ -282,31 +281,26 @@ _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa,
return -1; return -1;
if((ret = mbedtls_mpi_read_binary(&(ctx->E), edata, elen) ) != 0 || if((ret = mbedtls_mpi_read_binary(&(ctx->E), edata, elen) ) != 0 ||
(ret = mbedtls_mpi_read_binary(&(ctx->N), ndata, nlen) ) != 0 ) (ret = mbedtls_mpi_read_binary(&(ctx->N), ndata, nlen) ) != 0) {
{
ret = -1; ret = -1;
} }
if (!ret) if(!ret) {
{
ctx->len = mbedtls_mpi_size(&(ctx->N)); ctx->len = mbedtls_mpi_size(&(ctx->N));
} }
if (!ret && ddata) if(!ret && ddata) {
{
if((ret = mbedtls_mpi_read_binary(&(ctx->D), ddata, dlen) ) != 0 || if((ret = mbedtls_mpi_read_binary(&(ctx->D), ddata, dlen) ) != 0 ||
(ret = mbedtls_mpi_read_binary(&(ctx->P), pdata, plen) ) != 0 || (ret = mbedtls_mpi_read_binary(&(ctx->P), pdata, plen) ) != 0 ||
(ret = mbedtls_mpi_read_binary(&(ctx->Q), qdata, qlen) ) != 0 || (ret = mbedtls_mpi_read_binary(&(ctx->Q), qdata, qlen) ) != 0 ||
(ret = mbedtls_mpi_read_binary(&(ctx->DP), e1data, e1len) ) != 0 || (ret = mbedtls_mpi_read_binary(&(ctx->DP), e1data, e1len) ) != 0 ||
(ret = mbedtls_mpi_read_binary(&(ctx->DQ), e2data, e2len) ) != 0 || (ret = mbedtls_mpi_read_binary(&(ctx->DQ), e2data, e2len) ) != 0 ||
(ret = mbedtls_mpi_read_binary(&(ctx->QP), coeffdata, coefflen) ) != 0 ) (ret = mbedtls_mpi_read_binary(&(ctx->QP), coeffdata, coefflen) ) != 0) {
{
ret = -1; ret = -1;
} }
ret = mbedtls_rsa_check_privkey(ctx); ret = mbedtls_rsa_check_privkey(ctx);
} }
else if (!ret) else if(!ret) {
{
ret = mbedtls_rsa_check_pubkey(ctx); ret = mbedtls_rsa_check_pubkey(ctx);
} }
@@ -335,8 +329,7 @@ _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa,
mbedtls_pk_init(&pkey); mbedtls_pk_init(&pkey);
ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase); ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase);
if( ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
{
mbedtls_pk_free(&pkey); mbedtls_pk_free(&pkey);
mbedtls_rsa_free(*rsa); mbedtls_rsa_free(*rsa);
LIBSSH2_FREE(session, *rsa); LIBSSH2_FREE(session, *rsa);
@@ -369,8 +362,7 @@ _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata, ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata,
filedata_len, NULL, 0); filedata_len, NULL, 0);
if( ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
{
mbedtls_pk_free(&pkey); mbedtls_pk_free(&pkey);
mbedtls_rsa_free(*rsa); mbedtls_rsa_free(*rsa);
LIBSSH2_FREE(session, *rsa); LIBSSH2_FREE(session, *rsa);
@@ -499,19 +491,19 @@ _libssh2_mbedtls_pub_priv_key(LIBSSH2_SESSION *session,
size_t keylen = 0, mthlen = 0; size_t keylen = 0, mthlen = 0;
int ret; int ret;
if( mbedtls_pk_get_type(pkey) != MBEDTLS_PK_RSA ) if(mbedtls_pk_get_type(pkey) != MBEDTLS_PK_RSA) {
{
mbedtls_pk_free(pkey); mbedtls_pk_free(pkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Key type not supported"); "Key type not supported");
} }
// write method /* write method */
mthlen = 7; mthlen = 7;
mth = LIBSSH2_ALLOC(session, mthlen); mth = LIBSSH2_ALLOC(session, mthlen);
if(mth) { if(mth) {
memcpy(mth, "ssh-rsa", mthlen); memcpy(mth, "ssh-rsa", mthlen);
} else { }
else {
ret = -1; ret = -1;
} }
@@ -521,13 +513,14 @@ _libssh2_mbedtls_pub_priv_key(LIBSSH2_SESSION *session,
ret = -1; ret = -1;
} }
// write output /* write output */
if(ret) { if(ret) {
if(mth) if(mth)
LIBSSH2_FREE(session, mth); LIBSSH2_FREE(session, mth);
if(key) if(key)
LIBSSH2_FREE(session, key); LIBSSH2_FREE(session, key);
} else { }
else {
*method = mth; *method = mth;
*method_len = mthlen; *method_len = mthlen;
*pubkeydata = key; *pubkeydata = key;
@@ -552,8 +545,7 @@ _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session,
mbedtls_pk_init(&pkey); mbedtls_pk_init(&pkey);
ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase); ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase);
if( ret != 0 ) if(ret != 0) {
{
mbedtls_strerror(ret, (char *)buf, sizeof(buf)); mbedtls_strerror(ret, (char *)buf, sizeof(buf));
mbedtls_pk_free(&pkey); mbedtls_pk_free(&pkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf); return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf);
@@ -584,8 +576,7 @@ _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
mbedtls_pk_init(&pkey); mbedtls_pk_init(&pkey);
ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)privatekeydata, ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)privatekeydata,
privatekeydata_len, NULL, 0); privatekeydata_len, NULL, 0);
if( ret != 0 ) if(ret != 0) {
{
mbedtls_strerror(ret, (char *)buf, sizeof(buf)); mbedtls_strerror(ret, (char *)buf, sizeof(buf));
mbedtls_pk_free(&pkey); mbedtls_pk_free(&pkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf); return _libssh2_error(session, LIBSSH2_ERROR_FILE, buf);

View File

@@ -275,7 +275,8 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
} }
for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) { for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) {
if ((v = base64_reverse_table[*s]) < 0) v = base64_reverse_table[*s];
if(v < 0)
continue; continue;
switch(i % 4) { switch(i % 4) {
case 0: case 0:
@@ -622,8 +623,7 @@ int __cdecl _libssh2_gettimeofday(struct timeval *tp, void *tzp)
FILETIME ft; FILETIME ft;
} _now; } _now;
(void)tzp; (void)tzp;
if(tp) if(tp) {
{
GetSystemTimeAsFileTime(&_now.ft); GetSystemTimeAsFileTime(&_now.ft);
tp->tv_usec = (long)((_now.ns100 / 10) % 1000000); tp->tv_usec = (long)((_now.ns100 / 10) % 1000000);
tp->tv_sec = (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000); tp->tv_sec = (long)((_now.ns100 - _W32_FT_OFFSET) / 10000000);
@@ -669,8 +669,7 @@ void _libssh2_aes_ctr_increment(unsigned char *ctr,
pc = ctr + length - 1; pc = ctr + length - 1;
carry = 1; carry = 1;
while(pc >= ctr) while(pc >= ctr) {
{
val = (unsigned int)*pc + carry; val = (unsigned int)*pc + carry;
*pc-- = val & 0xFF; *pc-- = val & 0xFF;
carry = val >> 8; carry = val >> 8;

View File

@@ -368,9 +368,11 @@ _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx,
if(type == LIBSSH2_EC_CURVE_NISTP256) { if(type == LIBSSH2_EC_CURVE_NISTP256) {
LIBSSH2_ECDSA_VERIFY(256); LIBSSH2_ECDSA_VERIFY(256);
}else if ( type == LIBSSH2_EC_CURVE_NISTP384 ) { }
else if(type == LIBSSH2_EC_CURVE_NISTP384) {
LIBSSH2_ECDSA_VERIFY(384); LIBSSH2_ECDSA_VERIFY(384);
}else if ( type == LIBSSH2_EC_CURVE_NISTP521 ) { }
else if(type == LIBSSH2_EC_CURVE_NISTP521) {
LIBSSH2_ECDSA_VERIFY(512); LIBSSH2_ECDSA_VERIFY(512);
} }

View File

@@ -406,7 +406,8 @@ getASN1Element(asn1Element *elem, char *beg, char *end)
return NULL; return NULL;
elem->end = beg; elem->end = beg;
return beg + 1; return beg + 1;
} else if (beg + b > end) }
else if(beg + b > end)
return NULL; /* Does not fit in source. */ return NULL; /* Does not fit in source. */
else { else {
/* Get long length. */ /* Get long length. */
@@ -459,7 +460,8 @@ asn1_new(unsigned int type, unsigned int length)
length >>= 8; length >>= 8;
} while(length); } while(length);
} }
} else { }
else {
free((char *) e); free((char *) e);
e = NULL; e = NULL;
} }
@@ -810,7 +812,8 @@ _libssh2_bn_bits(_libssh2_bn *bn)
if(bn && bn->bignum) { if(bn && bn->bignum) {
for(i = bn->length; i--;) for(i = bn->length; i--;)
if ((b = bn->bignum[i])) { b = bn->bignum[i];
if(b) {
i *= 8; i *= 8;
do { do {
i++; i++;
@@ -1181,7 +1184,8 @@ _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
structkey = rsaprivatekeyinfo(key); structkey = rsaprivatekeyinfo(key);
} }
keytype = Qc3_RSA_Private; keytype = Qc3_RSA_Private;
} else if (!ret) { }
else if(!ret) {
key = rsapublickey(e, n); key = rsapublickey(e, n);
structkey = rsasubjectpublickeyinfo(key); structkey = rsasubjectpublickeyinfo(key);
keytype = Qc3_RSA_Public; keytype = Qc3_RSA_Public;
@@ -1378,7 +1382,8 @@ pbkdf1(LIBSSH2_SESSION *session, char **dk, const unsigned char * passphrase,
return -1; return -1;
/* Allocate the derived key buffer. */ /* Allocate the derived key buffer. */
if (!(*dk = LIBSSH2_ALLOC(session, pkcs5->hashlen))) *dk = LIBSSH2_ALLOC(session, pkcs5->hashlen);
if(!*dk)
return -1; return -1;
/* Initial hash. */ /* Initial hash. */
@@ -1431,7 +1436,8 @@ pbkdf2(LIBSSH2_SESSION *session, char **dk, const unsigned char * passphrase,
/* Allocate the derived key buffer. */ /* Allocate the derived key buffer. */
l = t; l = t;
if (!(buf = LIBSSH2_ALLOC(session, l * pkcs5->hashlen))) buf = LIBSSH2_ALLOC(session, l * pkcs5->hashlen);
if(!buf)
return -1; return -1;
*dk = buf; *dk = buf;
@@ -1875,7 +1881,8 @@ rsapkcs8pubkey(LIBSSH2_SESSION *session,
int pkilen; int pkilen;
Qus_EC_t errcode; Qus_EC_t errcode;
if (!(buf = alloca(datalen))) buf = alloca(datalen);
if(!buf)
return -1; return -1;
switch(pkcs8kek(session, &kekctx, data, datalen, passphrase, &pki)) { switch(pkcs8kek(session, &kekctx, data, datalen, passphrase, &pki)) {
@@ -2144,7 +2151,8 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
rsapkcs1pubkey, rsapkcs8pubkey, (void *) &p); rsapkcs1pubkey, rsapkcs8pubkey, (void *) &p);
if(!ret) { if(!ret) {
*method_len = strlen(p.method); *method_len = strlen(p.method);
if ((*method = LIBSSH2_ALLOC(session, *method_len))) *method = LIBSSH2_ALLOC(session, *method_len);
if(*method)
memcpy((char *) *method, p.method, *method_len); memcpy((char *) *method, p.method, *method_len);
else else
ret = -1; ret = -1;
@@ -2157,7 +2165,8 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, (void *) p.data); LIBSSH2_FREE(session, (void *) p.data);
*method = NULL; *method = NULL;
*method_len = 0; *method_len = 0;
} else { }
else {
*pubkeydata = (unsigned char *) p.data; *pubkeydata = (unsigned char *) p.data;
*pubkeydata_len = p.length; *pubkeydata_len = p.length;
} }
@@ -2200,7 +2209,8 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
/* Process PKCS#8. */ /* Process PKCS#8. */
ret = rsapkcs8privkey(session, ret = rsapkcs8privkey(session,
data, datalen, passphrase, (void *) &ctx); data, datalen, passphrase, (void *) &ctx);
} else { }
else {
/* Try with "RSA PRIVATE KEY" PEM armor. /* Try with "RSA PRIVATE KEY" PEM armor.
--> PKCS#1 RSAPrivateKey */ --> PKCS#1 RSAPrivateKey */
ret = _libssh2_pem_parse_memory(session, ret = _libssh2_pem_parse_memory(session,
@@ -2289,7 +2299,8 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
/* Process PKCS#8. */ /* Process PKCS#8. */
ret = rsapkcs8pubkey(session, ret = rsapkcs8pubkey(session,
data, datalen, passphrase, (void *) &p); data, datalen, passphrase, (void *) &p);
} else { }
else {
/* Try with "RSA PRIVATE KEY" PEM armor. /* Try with "RSA PRIVATE KEY" PEM armor.
--> PKCS#1 RSAPrivateKey */ --> PKCS#1 RSAPrivateKey */
ret = _libssh2_pem_parse_memory(session, ret = _libssh2_pem_parse_memory(session,
@@ -2319,7 +2330,8 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
if(!ret) { if(!ret) {
*method_len = strlen(p.method); *method_len = strlen(p.method);
if ((*method = LIBSSH2_ALLOC(session, *method_len))) *method = LIBSSH2_ALLOC(session, *method_len);
if(*method)
memcpy((char *) *method, p.method, *method_len); memcpy((char *) *method, p.method, *method_len);
else else
ret = -1; ret = -1;
@@ -2331,7 +2343,8 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, (void *) p.data); LIBSSH2_FREE(session, (void *) p.data);
*method = NULL; *method = NULL;
*method_len = 0; *method_len = 0;
} else { }
else {
*pubkeydata = (unsigned char *) p.data; *pubkeydata = (unsigned char *) p.data;
*pubkeydata_len = p.length; *pubkeydata_len = p.length;
} }

View File

@@ -245,7 +245,8 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
packet_len, NULL, 0); packet_len, NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
listen_state->state = libssh2_NB_state_idle; listen_state->state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, "Unable to send open failure"); return _libssh2_error(session, rc, "Unable to send open failure");
@@ -355,7 +356,8 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
NULL, 0); NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
x11open_state->state = libssh2_NB_state_idle; x11open_state->state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel open " "Unable to send channel open "
@@ -391,7 +393,8 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
NULL, 0); NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
x11open_state->state = libssh2_NB_state_idle; x11open_state->state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, "Unable to send open failure"); return _libssh2_error(session, rc, "Unable to send open failure");
} }
@@ -515,7 +518,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if(session->ssh_msg_ignore) { if(session->ssh_msg_ignore) {
LIBSSH2_IGNORE(session, (char *) data + 1, datalen - 1); LIBSSH2_IGNORE(session, (char *) data + 1, datalen - 1);
} }
} else if (session->ssh_msg_ignore) { }
else if(session->ssh_msg_ignore) {
LIBSSH2_IGNORE(session, "", 0); LIBSSH2_IGNORE(session, "", 0);
} }
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
@@ -1121,13 +1125,15 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
state->start = 0; state->start = 0;
/* an error which is not just because of blocking */ /* an error which is not just because of blocking */
return ret; return ret;
} else if (ret == packet_type) { }
else if(ret == packet_type) {
/* Be lazy, let packet_ask pull it out of the brigade */ /* Be lazy, let packet_ask pull it out of the brigade */
ret = _libssh2_packet_ask(session, packet_type, data, data_len, ret = _libssh2_packet_ask(session, packet_type, data, data_len,
match_ofs, match_buf, match_len); match_ofs, match_buf, match_len);
state->start = 0; state->start = 0;
return ret; return ret;
} else if (ret == 0) { }
else if(ret == 0) {
/* nothing available, wait until data arrives or we time out */ /* nothing available, wait until data arrives or we time out */
long left = LIBSSH2_READ_TIMEOUT - (long)(time(NULL) - long left = LIBSSH2_READ_TIMEOUT - (long)(time(NULL) -
state->start); state->start);
@@ -1183,10 +1189,12 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session,
ret = _libssh2_transport_read(session); ret = _libssh2_transport_read(session);
if(ret == LIBSSH2_ERROR_EAGAIN) { if(ret == LIBSSH2_ERROR_EAGAIN) {
return ret; return ret;
} else if (ret < 0) { }
else if(ret < 0) {
*state = libssh2_NB_state_idle; *state = libssh2_NB_state_idle;
return ret; return ret;
} else if (ret == 0) { }
else if(ret == 0) {
/* FIXME: this might busyloop */ /* FIXME: this might busyloop */
continue; continue;
} }

View File

@@ -374,7 +374,8 @@ read_asn1_length(const unsigned char *data,
*len <<= 8; *len <<= 8;
*len |= data[2]; *len |= data[2];
} }
} else { }
else {
lenlen = 0; lenlen = 0;
} }

View File

@@ -116,7 +116,8 @@ publickey_status_error(const LIBSSH2_PUBLICKEY *pkey,
if(status < 0 || status > LIBSSH2_PUBLICKEY_STATUS_CODE_MAX) { if(status < 0 || status > LIBSSH2_PUBLICKEY_STATUS_CODE_MAX) {
msg = "unknown"; msg = "unknown";
} else { }
else {
msg = publickey_status_codes[status].name; msg = publickey_status_codes[status].name;
} }
@@ -143,7 +144,8 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
rc = _libssh2_channel_read(channel, 0, (char *) buffer, 4); rc = _libssh2_channel_read(channel, 0, (char *) buffer, 4);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc != 4) { }
else if(rc != 4) {
return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid response from publickey subsystem"); "Invalid response from publickey subsystem");
} }
@@ -165,7 +167,8 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
pkey->receive_packet_len); pkey->receive_packet_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc != (int)pkey->receive_packet_len) { }
else if(rc != (int)pkey->receive_packet_len) {
LIBSSH2_FREE(session, pkey->receive_packet); LIBSSH2_FREE(session, pkey->receive_packet);
pkey->receive_packet = NULL; pkey->receive_packet = NULL;
pkey->receive_state = libssh2_NB_state_idle; pkey->receive_state = libssh2_NB_state_idle;
@@ -235,7 +238,8 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
int rc = publickey_packet_receive(pkey, &data, &data_len); int rc = publickey_packet_receive(pkey, &data, &data_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from " "Timeout waiting for response from "
"publickey subsystem"); "publickey subsystem");
@@ -330,7 +334,8 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting publickey subsystem"); "Would block starting publickey subsystem");
return NULL; return NULL;
} else if (rc) { }
else if(rc) {
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to request publickey subsystem"); "Unable to request publickey subsystem");
goto err_exit; goto err_exit;
@@ -385,7 +390,8 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending publickey version packet"); "Would block sending publickey version packet");
return NULL; return NULL;
} else if (rc < 0) { }
else if(rc < 0) {
_libssh2_error(session, rc, _libssh2_error(session, rc,
"Unable to send publickey version packet"); "Unable to send publickey version packet");
goto err_exit; goto err_exit;
@@ -411,7 +417,8 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session)
"Would block waiting for response from " "Would block waiting for response from "
"publickey subsystem"); "publickey subsystem");
return NULL; return NULL;
} else if (rc) { }
else if(rc) {
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from " "Timeout waiting for response from "
"publickey subsystem"); "publickey subsystem");
@@ -571,7 +578,8 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
} }
} }
packet_len += 4 + comment_len; packet_len += 4 + comment_len;
} else { }
else {
packet_len += 5; /* overwrite(1) + attribute_count(4) */ packet_len += 5; /* overwrite(1) + attribute_count(4) */
for(i = 0; i < num_attrs; i++) { for(i = 0; i < num_attrs; i++) {
packet_len += 9 + attrs[i].name_len + attrs[i].value_len; packet_len += 9 + attrs[i].name_len + attrs[i].value_len;
@@ -609,7 +617,8 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
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;
} else { }
else {
/* Version == 2 */ /* Version == 2 */
_libssh2_htonu32(pkey->add_s, name_len); _libssh2_htonu32(pkey->add_s, name_len);
@@ -649,7 +658,8 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name,
(pkey->add_s - pkey->add_packet)); (pkey->add_s - pkey->add_packet));
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if ((pkey->add_s - pkey->add_packet) != rc) { }
else if((pkey->add_s - pkey->add_packet) != rc) {
LIBSSH2_FREE(session, pkey->add_packet); LIBSSH2_FREE(session, pkey->add_packet);
pkey->add_packet = NULL; pkey->add_packet = NULL;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
@@ -732,7 +742,8 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
(pkey->remove_s - pkey->remove_packet)); (pkey->remove_s - pkey->remove_packet));
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if ((pkey->remove_s - pkey->remove_packet) != rc) { }
else if((pkey->remove_s - pkey->remove_packet) != rc) {
LIBSSH2_FREE(session, pkey->remove_packet); LIBSSH2_FREE(session, pkey->remove_packet);
pkey->remove_packet = NULL; pkey->remove_packet = NULL;
pkey->remove_state = libssh2_NB_state_idle; pkey->remove_state = libssh2_NB_state_idle;
@@ -800,7 +811,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
pkey->listFetch_buffer)); pkey->listFetch_buffer));
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) { }
else if((pkey->listFetch_s - pkey->listFetch_buffer) != rc) {
pkey->listFetch_state = libssh2_NB_state_idle; pkey->listFetch_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey list packet"); "Unable to send publickey list packet");
@@ -814,7 +826,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
&pkey->listFetch_data_len); &pkey->listFetch_data_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from " "Timeout waiting for response from "
"publickey subsystem"); "publickey subsystem");
@@ -907,7 +920,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
list[keys].attrs[0].mandatory = 0; list[keys].attrs[0].mandatory = 0;
pkey->listFetch_s += comment_len; pkey->listFetch_s += comment_len;
} else { }
else {
list[keys].num_attrs = 0; list[keys].num_attrs = 0;
list[keys].attrs = NULL; list[keys].attrs = NULL;
} }
@@ -919,7 +933,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
pkey->listFetch_s += 4; pkey->listFetch_s += 4;
list[keys].blob = pkey->listFetch_s; list[keys].blob = pkey->listFetch_s;
pkey->listFetch_s += list[keys].blob_len; pkey->listFetch_s += list[keys].blob_len;
} else { }
else {
/* Version == 2 */ /* Version == 2 */
list[keys].name_len = _libssh2_ntohu32(pkey->listFetch_s); list[keys].name_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4; pkey->listFetch_s += 4;
@@ -957,7 +972,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
/* actually an ignored value */ /* actually an ignored value */
list[keys].attrs[i].mandatory = 0; list[keys].attrs[i].mandatory = 0;
} }
} else { }
else {
list[keys].attrs = NULL; list[keys].attrs = NULL;
} }
} }

View File

@@ -347,7 +347,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting SCP startup"); "Would block requesting SCP startup");
return NULL; return NULL;
} else if (rc) { }
else if(rc) {
LIBSSH2_FREE(session, session->scpRecv_command); LIBSSH2_FREE(session, session->scpRecv_command);
session->scpRecv_command = NULL; session->scpRecv_command = NULL;
goto scp_recv_error; goto scp_recv_error;
@@ -369,7 +370,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending initial wakeup"); "Would block sending initial wakeup");
return NULL; return NULL;
} else if (rc != 1) { }
else if(rc != 1) {
goto scp_recv_error; goto scp_recv_error;
} }
@@ -551,7 +553,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting to send SCP ACK"); "Would block waiting to send SCP ACK");
return NULL; return NULL;
} else if (rc != 1) { }
else if(rc != 1) {
goto scp_recv_error; goto scp_recv_error;
} }
@@ -707,7 +710,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending SCP ACK"); "Would block sending SCP ACK");
return NULL; return NULL;
} else if (rc != 1) { }
else if(rc != 1) {
goto scp_recv_error; goto scp_recv_error;
} }
_libssh2_debug(session, LIBSSH2_TRACE_SCP, _libssh2_debug(session, LIBSSH2_TRACE_SCP,
@@ -948,7 +952,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending time data for SCP file"); "Would block sending time data for SCP file");
return NULL; return NULL;
} else if (rc != (int)session->scpSend_response_len) { }
else if(rc != (int)session->scpSend_response_len) {
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send time data for SCP file"); "Unable to send time data for SCP file");
goto scp_send_error; goto scp_send_error;
@@ -981,7 +986,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_state = libssh2_NB_state_sent4; session->scpSend_state = libssh2_NB_state_sent4;
} }
} else { }
else {
if(session->scpSend_state == libssh2_NB_state_sent2) { if(session->scpSend_state == libssh2_NB_state_sent2) {
session->scpSend_state = libssh2_NB_state_sent4; session->scpSend_state = libssh2_NB_state_sent4;
} }
@@ -1014,7 +1020,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block send core file data for SCP file"); "Would block send core file data for SCP file");
return NULL; return NULL;
} else if (rc != (int)session->scpSend_response_len) { }
else if(rc != (int)session->scpSend_response_len) {
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send core file data for SCP file"); "Unable to send core file data for SCP file");
goto scp_send_error; goto scp_send_error;

View File

@@ -103,7 +103,8 @@ banner_receive(LIBSSH2_SESSION * session)
banner_len = 0; banner_len = 0;
session->banner_TxRx_state = libssh2_NB_state_created; session->banner_TxRx_state = libssh2_NB_state_created;
} else { }
else {
banner_len = session->banner_TxRx_total_send; banner_len = session->banner_TxRx_total_send;
} }
@@ -212,7 +213,8 @@ banner_send(LIBSSH2_SESSION * session)
if(banner_len < 256) { if(banner_len < 256) {
memcpy(banner_dup, banner, banner_len - 2); memcpy(banner_dup, banner, banner_len - 2);
banner_dup[banner_len - 2] = '\0'; banner_dup[banner_len - 2] = '\0';
} else { }
else {
memcpy(banner_dup, banner, 255); memcpy(banner_dup, banner, 255);
banner[255] = '\0'; banner[255] = '\0';
} }
@@ -344,9 +346,9 @@ get_socket_nonblocking(int sockfd)
#define GETBLOCK 0 #define GETBLOCK 0
#ifdef HAVE_O_NONBLOCK #ifdef HAVE_O_NONBLOCK
/* most recent unix versions */ /* most recent unix versions */
int flags; int flags = fcntl(sockfd, F_GETFL, 0);
if ((flags = fcntl(sockfd, F_GETFL, 0)) == -1) { if(flags == -1) {
/* Assume blocking on error */ /* Assume blocking on error */
return 1; return 1;
} }
@@ -392,9 +394,9 @@ get_socket_nonblocking(int sockfd)
callstat = getsockopt(sockfd, SOL_SOCKET, SO_STATE, callstat = getsockopt(sockfd, SOL_SOCKET, SO_STATE,
(char *)&sockstat, &size); (char *)&sockstat, &size);
if ( callstat == -1 ) return(0); if(callstat == -1) return 0;
if ( (sockstat&SS_NBIO) )return(1); if((sockstat&SS_NBIO) != 0) return 1;
return(0); return 0;
#undef GETBLOCK #undef GETBLOCK
#define GETBLOCK 6 #define GETBLOCK 6
@@ -1257,7 +1259,8 @@ libssh2_session_last_error(LIBSSH2_SESSION * session, char **errmsg,
if(*errmsg) { if(*errmsg) {
**errmsg = 0; **errmsg = 0;
} }
} else { }
else {
*errmsg = (char *) ""; *errmsg = (char *) "";
} }
} }
@@ -1426,7 +1429,8 @@ libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended)
(packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA (packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA
|| packet->data[0] == SSH_MSG_CHANNEL_DATA)) { || packet->data[0] == SSH_MSG_CHANNEL_DATA)) {
return 1; return 1;
} else if ( extended == 0 && }
else if(extended == 0 &&
packet->data[0] == SSH_MSG_CHANNEL_DATA) { packet->data[0] == SSH_MSG_CHANNEL_DATA) {
return 1; return 1;
} }

View File

@@ -570,7 +570,8 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses,
if((rc < 0) && (rc != LIBSSH2_ERROR_EAGAIN)) { if((rc < 0) && (rc != LIBSSH2_ERROR_EAGAIN)) {
sftp->requirev_start = 0; sftp->requirev_start = 0;
return rc; return rc;
} else if (rc <= 0) { }
else if(rc <= 0) {
/* prevent busy-looping */ /* prevent busy-looping */
long left = long left =
LIBSSH2_READ_TIMEOUT - (long)(time(NULL) - sftp->requirev_start); LIBSSH2_READ_TIMEOUT - (long)(time(NULL) - sftp->requirev_start);
@@ -765,7 +766,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block to request SFTP subsystem"); "Would block to request SFTP subsystem");
return NULL; return NULL;
} else if (ret) { }
else if(ret) {
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to request SFTP subsystem"); "Unable to request SFTP subsystem");
goto sftp_init_error; goto sftp_init_error;
@@ -1312,7 +1314,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
if(filep->eof) { if(filep->eof) {
return 0; return 0;
} else { }
else {
/* We allow a number of bytes being requested at any given time /* We allow a number of bytes being requested at any given time
without having been acked - until we reach EOF. */ without having been acked - until we reach EOF. */
@@ -1443,7 +1446,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
* we can get out of this loop and start reading. */ * we can get out of this loop and start reading. */
if(chunk != _libssh2_list_first(&handle->packet_list)) { if(chunk != _libssh2_list_first(&handle->packet_list)) {
break; break;
} else { }
else {
continue; continue;
} }
} }
@@ -1475,7 +1479,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
for an ACK for it just yet */ for an ACK for it just yet */
if(bytes_in_buffer > 0) { if(bytes_in_buffer > 0) {
return bytes_in_buffer; return bytes_in_buffer;
} else { }
else {
/* we should never reach this point */ /* we should never reach this point */
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"sftp_read() internal error"); "sftp_read() internal error");
@@ -1594,7 +1599,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
*/ */
if(bytes_in_buffer < buffer_size) { if(bytes_in_buffer < buffer_size) {
chunk = next; chunk = next;
} else { }
else {
chunk = NULL; chunk = NULL;
} }
@@ -1876,7 +1882,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
default: default:
case libssh2_NB_state_idle: case libssh2_NB_state_idle:
/* Number of bytes sent off that haven't been acked and therefor we /* Number of bytes sent off that haven't been acked and therefore we
will get passed in here again. will get passed in here again.
Also, add up the number of bytes that actually already have been Also, add up the number of bytes that actually already have been
@@ -2103,7 +2109,8 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
_libssh2_store_str(&s, handle->handle, handle->handle_len); _libssh2_store_str(&s, handle->handle, handle->handle_len);
sftp->fsync_state = libssh2_NB_state_created; sftp->fsync_state = libssh2_NB_state_created;
} else { }
else {
packet = sftp->fsync_packet; packet = sftp->fsync_packet;
} }
@@ -2130,7 +2137,8 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
sftp->fsync_request_id, &data, &data_len); sftp->fsync_request_id, &data, &data_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
sftp->fsync_state = libssh2_NB_state_idle; sftp->fsync_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Error waiting for FXP EXTENDED REPLY"); "Error waiting for FXP EXTENDED REPLY");
@@ -2248,7 +2256,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
if(retcode == LIBSSH2_FX_OK) { if(retcode == LIBSSH2_FX_OK) {
return 0; return 0;
} else { }
else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
@@ -2402,7 +2411,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_CLOSE " "Unable to allocate memory for FXP_CLOSE "
"packet"); "packet");
} else { }
else {
_libssh2_store_u32(&s, packet_len - 4); _libssh2_store_u32(&s, packet_len - 4);
*(s++) = SSH_FXP_CLOSE; *(s++) = SSH_FXP_CLOSE;
@@ -2418,11 +2428,13 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
packet_len); packet_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if ((ssize_t)packet_len != rc) { }
else if((ssize_t)packet_len != rc) {
handle->close_state = libssh2_NB_state_idle; handle->close_state = libssh2_NB_state_idle;
rc = _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, rc = _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_CLOSE command"); "Unable to send FXP_CLOSE command");
} else }
else
handle->close_state = libssh2_NB_state_sent; handle->close_state = libssh2_NB_state_sent;
LIBSSH2_FREE(session, handle->close_packet); LIBSSH2_FREE(session, handle->close_packet);
@@ -2436,7 +2448,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
_libssh2_error(session, rc, _libssh2_error(session, rc,
"Error waiting for status message"); "Error waiting for status message");
} }
@@ -2449,7 +2462,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
happened for which we should have set an error code */ happened for which we should have set an error code */
assert(rc); assert(rc);
} else { }
else {
int retcode = _libssh2_ntohu32(data + 5); int retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
@@ -2535,7 +2549,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
packet_len); packet_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if ((ssize_t)packet_len != rc) { }
else if((ssize_t)packet_len != rc) {
LIBSSH2_FREE(session, sftp->unlink_packet); LIBSSH2_FREE(session, sftp->unlink_packet);
sftp->unlink_packet = NULL; sftp->unlink_packet = NULL;
sftp->unlink_state = libssh2_NB_state_idle; sftp->unlink_state = libssh2_NB_state_idle;
@@ -2567,7 +2582,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
if(retcode == LIBSSH2_FX_OK) { if(retcode == LIBSSH2_FX_OK) {
return 0; return 0;
} else { }
else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
@@ -2646,7 +2662,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
sftp->rename_s - sftp->rename_packet); sftp->rename_s - sftp->rename_packet);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if ((ssize_t)packet_len != rc) { }
else if((ssize_t)packet_len != rc) {
LIBSSH2_FREE(session, sftp->rename_packet); LIBSSH2_FREE(session, sftp->rename_packet);
sftp->rename_packet = NULL; sftp->rename_packet = NULL;
sftp->rename_state = libssh2_NB_state_idle; sftp->rename_state = libssh2_NB_state_idle;
@@ -2664,7 +2681,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
&data_len); &data_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
sftp->rename_state = libssh2_NB_state_idle; sftp->rename_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Error waiting for FXP STATUS"); "Error waiting for FXP STATUS");
@@ -2790,7 +2808,8 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
sftp->fstatvfs_state = libssh2_NB_state_idle; sftp->fstatvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Error waiting for FXP EXTENDED REPLY"); "Error waiting for FXP EXTENDED REPLY");
@@ -2916,7 +2935,8 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
&data, &data_len); &data, &data_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
sftp->statvfs_state = libssh2_NB_state_idle; sftp->statvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Error waiting for FXP EXTENDED REPLY"); "Error waiting for FXP EXTENDED REPLY");
@@ -3046,7 +3066,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
&data, &data_len); &data, &data_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
sftp->mkdir_state = libssh2_NB_state_idle; sftp->mkdir_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Error waiting for FXP STATUS"); "Error waiting for FXP STATUS");
@@ -3060,7 +3081,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
if(retcode == LIBSSH2_FX_OK) { if(retcode == LIBSSH2_FX_OK) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "OK!"); _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "OK!");
return 0; return 0;
} else { }
else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
@@ -3123,7 +3145,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
packet_len); packet_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (packet_len != rc) { }
else if(packet_len != rc) {
LIBSSH2_FREE(session, sftp->rmdir_packet); LIBSSH2_FREE(session, sftp->rmdir_packet);
sftp->rmdir_packet = NULL; sftp->rmdir_packet = NULL;
sftp->rmdir_state = libssh2_NB_state_idle; sftp->rmdir_state = libssh2_NB_state_idle;
@@ -3140,7 +3163,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
sftp->rmdir_request_id, &data, &data_len); sftp->rmdir_request_id, &data, &data_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (rc) { }
else if(rc) {
sftp->rmdir_state = libssh2_NB_state_idle; sftp->rmdir_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc, return _libssh2_error(session, rc,
"Error waiting for FXP STATUS"); "Error waiting for FXP STATUS");
@@ -3153,7 +3177,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
if(retcode == LIBSSH2_FX_OK) { if(retcode == LIBSSH2_FX_OK) {
return 0; return 0;
} else { }
else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
@@ -3236,7 +3261,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
rc = _libssh2_channel_write(channel, 0, sftp->stat_packet, packet_len); rc = _libssh2_channel_write(channel, 0, sftp->stat_packet, packet_len);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc; return rc;
} else if (packet_len != rc) { }
else if(packet_len != rc) {
LIBSSH2_FREE(session, sftp->stat_packet); LIBSSH2_FREE(session, sftp->stat_packet);
sftp->stat_packet = NULL; sftp->stat_packet = NULL;
sftp->stat_state = libssh2_NB_state_idle; sftp->stat_state = libssh2_NB_state_idle;
@@ -3268,7 +3294,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
if(retcode == LIBSSH2_FX_OK) { if(retcode == LIBSSH2_FX_OK) {
return 0; return 0;
} else { }
else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");

View File

@@ -329,7 +329,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
if(session->state & LIBSSH2_STATE_NEWKEYS) { if(session->state & LIBSSH2_STATE_NEWKEYS) {
blocksize = session->remote.crypt->blocksize; blocksize = session->remote.crypt->blocksize;
} else { }
else {
encrypted = 0; /* not encrypted */ encrypted = 0; /* not encrypted */
blocksize = 5; /* not strictly true, but we can use 5 here to blocksize = 5; /* not strictly true, but we can use 5 here to
make the checks below work fine still */ make the checks below work fine still */
@@ -359,7 +360,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
memmove(p->buf, &p->buf[p->readidx], remainbuf); memmove(p->buf, &p->buf[p->readidx], remainbuf);
p->readidx = 0; p->readidx = 0;
p->writeidx = remainbuf; p->writeidx = remainbuf;
} else { }
else {
/* nothing to move, just zero the indexes */ /* nothing to move, just zero the indexes */
p->readidx = p->writeidx = 0; p->readidx = p->writeidx = 0;
} }
@@ -421,7 +423,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
/* save the first 5 bytes of the decrypted package, to be /* save the first 5 bytes of the decrypted package, to be
used in the hash calculation later down. */ used in the hash calculation later down. */
memcpy(p->init, block, 5); memcpy(p->init, block, 5);
} else { }
else {
/* the data is plain, just copy it verbatim to /* the data is plain, just copy it verbatim to
the working block buffer */ the working block buffer */
memcpy(block, &p->buf[p->readidx], blocksize); memcpy(block, &p->buf[p->readidx], blocksize);
@@ -505,7 +508,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
amount to decrypt even more */ amount to decrypt even more */
if((p->data_num + numbytes) > (p->total_num - skip)) { if((p->data_num + numbytes) > (p->total_num - skip)) {
numdecrypt = (p->total_num - skip) - p->data_num; numdecrypt = (p->total_num - skip) - p->data_num;
} else { }
else {
int frac; int frac;
numdecrypt = numbytes; numdecrypt = numbytes;
frac = numdecrypt % blocksize; frac = numdecrypt % blocksize;
@@ -518,7 +522,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
numbytes = 0; numbytes = 0;
} }
} }
} else { }
else {
/* unencrypted data should not be decrypted at all */ /* unencrypted data should not be decrypted at all */
numdecrypt = 0; numdecrypt = 0;
} }
@@ -566,8 +571,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
rc = fullpacket(session, encrypted); rc = fullpacket(session, encrypted);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
if (session->packAdd_state != libssh2_NB_state_idle) if(session->packAdd_state != libssh2_NB_state_idle) {
{
/* fullpacket only returns LIBSSH2_ERROR_EAGAIN if /* fullpacket only returns LIBSSH2_ERROR_EAGAIN if
* libssh2_packet_add returns LIBSSH2_ERROR_EAGAIN. If that * libssh2_packet_add returns LIBSSH2_ERROR_EAGAIN. If that
* returns LIBSSH2_ERROR_EAGAIN but the packAdd_state is idle, * returns LIBSSH2_ERROR_EAGAIN but the packAdd_state is idle,

View File

@@ -127,7 +127,8 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list"); "Would block requesting userauth list");
return NULL; return NULL;
} else if (rc) { }
else if(rc) {
_libssh2_error(session, rc, "Failed getting response"); _libssh2_error(session, rc, "Failed getting response");
session->userauth_list_state = libssh2_NB_state_idle; session->userauth_list_state = libssh2_NB_state_idle;
return NULL; return NULL;
@@ -294,7 +295,8 @@ userauth_password(LIBSSH2_SESSION *session,
session->state |= LIBSSH2_STATE_AUTHENTICATED; session->state |= LIBSSH2_STATE_AUTHENTICATED;
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return 0; return 0;
} else if (session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_FAILURE) { }
else if(session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_FAILURE) {
_libssh2_debug(session, LIBSSH2_TRACE_AUTH, _libssh2_debug(session, LIBSSH2_TRACE_AUTH,
"Password authentication failed"); "Password authentication failed");
LIBSSH2_FREE(session, session->userauth_pswd_data); LIBSSH2_FREE(session, session->userauth_pswd_data);
@@ -404,7 +406,8 @@ userauth_password(LIBSSH2_SESSION *session,
goto password_response; goto password_response;
} }
} }
} else { }
else {
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED, return _libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED,
"Password Expired, and no callback " "Password Expired, and no callback "
@@ -479,7 +482,8 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
"Missing public key data"); "Missing public key data");
} }
if ((sp1 = memchr(pubkey, ' ', pubkey_len)) == NULL) { sp1 = memchr(pubkey, ' ', pubkey_len);
if(sp1 == NULL) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid public key data"); "Invalid public key data");
@@ -487,7 +491,8 @@ memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
sp1++; sp1++;
if ((sp2 = memchr(sp1, ' ', pubkey_len - (sp1 - pubkey - 1))) == NULL) { sp2 = memchr(sp1, ' ', pubkey_len - (sp1 - pubkey - 1));
if(sp2 == NULL) {
/* Assume that the id string is missing, but that it's okay */ /* Assume that the id string is missing, but that it's okay */
sp2 = pubkey + pubkey_len; sp2 = pubkey + pubkey_len;
} }
@@ -580,7 +585,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
"Missing public key data"); "Missing public key data");
} }
if ((sp1 = memchr(pubkey, ' ', pubkey_len)) == NULL) { sp1 = memchr(pubkey, ' ', pubkey_len);
if(sp1 == NULL) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
return _libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid public key data"); "Invalid public key data");
@@ -589,7 +595,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
sp1++; sp1++;
sp_len = sp1 > pubkey ? (sp1 - pubkey) - 1 : 0; sp_len = sp1 > pubkey ? (sp1 - pubkey) - 1 : 0;
if ((sp2 = memchr(sp1, ' ', pubkey_len - sp_len)) == NULL) { sp2 = memchr(sp1, ' ', pubkey_len - sp_len);
if(sp2 == NULL) {
/* Assume that the id string is missing, but that it's okay */ /* Assume that the id string is missing, but that it's okay */
sp2 = pubkey + pubkey_len; sp2 = pubkey + pubkey_len;
} }
@@ -1250,7 +1257,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, buf); LIBSSH2_FREE(session, buf);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
} else if (rc) { }
else if(rc) {
LIBSSH2_FREE(session, session->userauth_pblc_method); LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL; session->userauth_pblc_method = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_packet); LIBSSH2_FREE(session, session->userauth_pblc_packet);
@@ -1314,7 +1322,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
NULL, 0); NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
} else if (rc) { }
else if(rc) {
LIBSSH2_FREE(session, session->userauth_pblc_packet); LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL; session->userauth_pblc_packet = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
@@ -1337,7 +1346,8 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session,
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list"); "Would block requesting userauth list");
} else if (rc) { }
else if(rc) {
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Waiting for publickey USERAUTH response"); "Waiting for publickey USERAUTH response");
@@ -1645,7 +1655,8 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
NULL, 0); NULL, 0);
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
} else if (rc) { }
else if(rc) {
LIBSSH2_FREE(session, session->userauth_kybd_data); LIBSSH2_FREE(session, session->userauth_kybd_data);
session->userauth_kybd_data = NULL; session->userauth_kybd_data = NULL;
session->userauth_kybd_state = libssh2_NB_state_idle; session->userauth_kybd_state = libssh2_NB_state_idle;
@@ -1669,7 +1680,8 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block"); "Would block");
} else if (rc) { }
else if(rc) {
session->userauth_kybd_state = libssh2_NB_state_idle; session->userauth_kybd_state = libssh2_NB_state_idle;
return _libssh2_error(session, return _libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED, LIBSSH2_ERROR_AUTHENTICATION_FAILED,

View File

@@ -246,7 +246,8 @@ _libssh2_wincng_init(void)
ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlgAES_CBC, ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlgAES_CBC,
BCRYPT_AES_ALGORITHM, NULL, 0); BCRYPT_AES_ALGORITHM, NULL, 0);
if(BCRYPT_SUCCESS(ret)) { if(BCRYPT_SUCCESS(ret)) {
ret = BCryptSetProperty(_libssh2_wincng.hAlgAES_CBC, BCRYPT_CHAINING_MODE, ret = BCryptSetProperty(_libssh2_wincng.hAlgAES_CBC,
BCRYPT_CHAINING_MODE,
(PBYTE)BCRYPT_CHAIN_MODE_CBC, (PBYTE)BCRYPT_CHAIN_MODE_CBC,
sizeof(BCRYPT_CHAIN_MODE_CBC), 0); sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
if(!BCRYPT_SUCCESS(ret)) { if(!BCRYPT_SUCCESS(ret)) {
@@ -257,7 +258,8 @@ _libssh2_wincng_init(void)
ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlgAES_ECB, ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlgAES_ECB,
BCRYPT_AES_ALGORITHM, NULL, 0); BCRYPT_AES_ALGORITHM, NULL, 0);
if(BCRYPT_SUCCESS(ret)) { if(BCRYPT_SUCCESS(ret)) {
ret = BCryptSetProperty(_libssh2_wincng.hAlgAES_ECB, BCRYPT_CHAINING_MODE, ret = BCryptSetProperty(_libssh2_wincng.hAlgAES_ECB,
BCRYPT_CHAINING_MODE,
(PBYTE)BCRYPT_CHAIN_MODE_ECB, (PBYTE)BCRYPT_CHAIN_MODE_ECB,
sizeof(BCRYPT_CHAIN_MODE_ECB), 0); sizeof(BCRYPT_CHAIN_MODE_ECB), 0);
if(!BCRYPT_SUCCESS(ret)) { if(!BCRYPT_SUCCESS(ret)) {
@@ -268,7 +270,8 @@ _libssh2_wincng_init(void)
ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlgRC4_NA, ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlgRC4_NA,
BCRYPT_RC4_ALGORITHM, NULL, 0); BCRYPT_RC4_ALGORITHM, NULL, 0);
if(BCRYPT_SUCCESS(ret)) { if(BCRYPT_SUCCESS(ret)) {
ret = BCryptSetProperty(_libssh2_wincng.hAlgRC4_NA, BCRYPT_CHAINING_MODE, ret = BCryptSetProperty(_libssh2_wincng.hAlgRC4_NA,
BCRYPT_CHAINING_MODE,
(PBYTE)BCRYPT_CHAIN_MODE_NA, (PBYTE)BCRYPT_CHAIN_MODE_NA,
sizeof(BCRYPT_CHAIN_MODE_NA), 0); sizeof(BCRYPT_CHAIN_MODE_NA), 0);
if(!BCRYPT_SUCCESS(ret)) { if(!BCRYPT_SUCCESS(ret)) {
@@ -279,7 +282,8 @@ _libssh2_wincng_init(void)
ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlg3DES_CBC, ret = BCryptOpenAlgorithmProvider(&_libssh2_wincng.hAlg3DES_CBC,
BCRYPT_3DES_ALGORITHM, NULL, 0); BCRYPT_3DES_ALGORITHM, NULL, 0);
if(BCRYPT_SUCCESS(ret)) { if(BCRYPT_SUCCESS(ret)) {
ret = BCryptSetProperty(_libssh2_wincng.hAlg3DES_CBC, BCRYPT_CHAINING_MODE, ret = BCryptSetProperty(_libssh2_wincng.hAlg3DES_CBC,
BCRYPT_CHAINING_MODE,
(PBYTE)BCRYPT_CHAIN_MODE_CBC, (PBYTE)BCRYPT_CHAIN_MODE_CBC,
sizeof(BCRYPT_CHAIN_MODE_CBC), 0); sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
if(!BCRYPT_SUCCESS(ret)) { if(!BCRYPT_SUCCESS(ret)) {
@@ -522,7 +526,8 @@ _libssh2_wincng_key_sha1_verify(_libssh2_wincng_key_ctx *ctx,
if(flags & BCRYPT_PAD_PKCS1) { if(flags & BCRYPT_PAD_PKCS1) {
paddingInfoPKCS1.pszAlgId = BCRYPT_SHA1_ALGORITHM; paddingInfoPKCS1.pszAlgId = BCRYPT_SHA1_ALGORITHM;
pPaddingInfo = &paddingInfoPKCS1; pPaddingInfo = &paddingInfoPKCS1;
} else }
else
pPaddingInfo = NULL; pPaddingInfo = NULL;
memcpy(data, sig, datalen); memcpy(data, sig, datalen);
@@ -775,7 +780,8 @@ _libssh2_wincng_asn_decode_bns(unsigned char *pbEncoded,
*prpbDecoded = rpbDecoded; *prpbDecoded = rpbDecoded;
*prcbDecoded = rcbDecoded; *prcbDecoded = rcbDecoded;
*pcbCount = length; *pcbCount = length;
} else { }
else {
for(length = 0; length < index; length++) { for(length = 0; length < index; length++) {
_libssh2_wincng_safe_free(rpbDecoded[length], _libssh2_wincng_safe_free(rpbDecoded[length],
rcbDecoded[length]); rcbDecoded[length]);
@@ -785,11 +791,13 @@ _libssh2_wincng_asn_decode_bns(unsigned char *pbEncoded,
free(rpbDecoded); free(rpbDecoded);
free(rcbDecoded); free(rcbDecoded);
} }
} else { }
else {
free(rpbDecoded); free(rpbDecoded);
ret = -1; ret = -1;
} }
} else { }
else {
ret = -1; ret = -1;
} }
@@ -928,7 +936,8 @@ _libssh2_wincng_rsa_new(libssh2_rsa_ctx **rsa,
rsakey->Magic = BCRYPT_RSAFULLPRIVATE_MAGIC; rsakey->Magic = BCRYPT_RSAFULLPRIVATE_MAGIC;
rsakey->cbPrime1 = p1len; rsakey->cbPrime1 = p1len;
rsakey->cbPrime2 = p2len; rsakey->cbPrime2 = p2len;
} else { }
else {
lpszBlobType = BCRYPT_RSAPUBLIC_BLOB; lpszBlobType = BCRYPT_RSAPUBLIC_BLOB;
rsakey->Magic = BCRYPT_RSAPUBLIC_MAGIC; rsakey->Magic = BCRYPT_RSAPUBLIC_MAGIC;
rsakey->cbPrime1 = 0; rsakey->cbPrime1 = 0;
@@ -1122,10 +1131,12 @@ _libssh2_wincng_rsa_sha1_sign(LIBSSH2_SESSION *session,
if(BCRYPT_SUCCESS(ret)) { if(BCRYPT_SUCCESS(ret)) {
*signature_len = siglen; *signature_len = siglen;
*signature = sig; *signature = sig;
} else { }
else {
LIBSSH2_FREE(session, sig); LIBSSH2_FREE(session, sig);
} }
} else }
else
ret = STATUS_NO_MEMORY; ret = STATUS_NO_MEMORY;
} }
@@ -1229,7 +1240,8 @@ _libssh2_wincng_dsa_new(libssh2_dsa_ctx **dsa,
lpszBlobType = BCRYPT_DSA_PRIVATE_BLOB; lpszBlobType = BCRYPT_DSA_PRIVATE_BLOB;
dsakey->dwMagic = BCRYPT_DSA_PRIVATE_MAGIC; dsakey->dwMagic = BCRYPT_DSA_PRIVATE_MAGIC;
} else { }
else {
lpszBlobType = BCRYPT_DSA_PUBLIC_BLOB; lpszBlobType = BCRYPT_DSA_PUBLIC_BLOB;
dsakey->dwMagic = BCRYPT_DSA_PUBLIC_MAGIC; dsakey->dwMagic = BCRYPT_DSA_PUBLIC_MAGIC;
} }
@@ -1287,7 +1299,8 @@ _libssh2_wincng_dsa_new_private_parse(libssh2_dsa_ctx **dsa,
rpbDecoded[3], rcbDecoded[3], rpbDecoded[3], rcbDecoded[3],
rpbDecoded[4], rcbDecoded[4], rpbDecoded[4], rcbDecoded[4],
rpbDecoded[5], rcbDecoded[5]); rpbDecoded[5], rcbDecoded[5]);
} else { }
else {
ret = -1; ret = -1;
} }
@@ -1409,9 +1422,11 @@ _libssh2_wincng_dsa_sha1_sign(libssh2_dsa_ctx *dsa,
} }
_libssh2_wincng_safe_free(sig, siglen); _libssh2_wincng_safe_free(sig, siglen);
} else }
else
ret = STATUS_NO_MEMORY; ret = STATUS_NO_MEMORY;
} else }
else
ret = STATUS_NO_MEMORY; ret = STATUS_NO_MEMORY;
} }
@@ -1487,7 +1502,8 @@ _libssh2_wincng_pub_priv_keyfile_parse(LIBSSH2_SESSION *session,
mth = LIBSSH2_ALLOC(session, mthlen); mth = LIBSSH2_ALLOC(session, mthlen);
if(mth) { if(mth) {
memcpy(mth, "ssh-rsa", mthlen); memcpy(mth, "ssh-rsa", mthlen);
} else { }
else {
ret = -1; ret = -1;
} }
@@ -1504,16 +1520,19 @@ _libssh2_wincng_pub_priv_keyfile_parse(LIBSSH2_SESSION *session,
_libssh2_wincng_pub_priv_write(key, offset, _libssh2_wincng_pub_priv_write(key, offset,
rpbDecoded[1], rpbDecoded[1],
rcbDecoded[1]); rcbDecoded[1]);
} else { }
else {
ret = -1; ret = -1;
} }
} else if (length == 6) { /* private DSA key */ }
else if(length == 6) { /* private DSA key */
mthlen = 7; mthlen = 7;
mth = LIBSSH2_ALLOC(session, mthlen); mth = LIBSSH2_ALLOC(session, mthlen);
if(mth) { if(mth) {
memcpy(mth, "ssh-dss", mthlen); memcpy(mth, "ssh-dss", mthlen);
} else { }
else {
ret = -1; ret = -1;
} }
@@ -1538,11 +1557,13 @@ _libssh2_wincng_pub_priv_keyfile_parse(LIBSSH2_SESSION *session,
_libssh2_wincng_pub_priv_write(key, offset, _libssh2_wincng_pub_priv_write(key, offset,
rpbDecoded[4], rpbDecoded[4],
rcbDecoded[4]); rcbDecoded[4]);
} else { }
else {
ret = -1; ret = -1;
} }
} else { }
else {
ret = -1; ret = -1;
} }
@@ -1562,7 +1583,8 @@ _libssh2_wincng_pub_priv_keyfile_parse(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, mth); LIBSSH2_FREE(session, mth);
if(key) if(key)
LIBSSH2_FREE(session, key); LIBSSH2_FREE(session, key);
} else { }
else {
*method = mth; *method = mth;
*method_len = mthlen; *method_len = mthlen;
*pubkeydata = key; *pubkeydata = key;
@@ -1665,7 +1687,8 @@ _libssh2_wincng_cipher_init(_libssh2_cipher_ctx *ctx,
BCRYPT_KEY_HANDLE hKey; BCRYPT_KEY_HANDLE hKey;
BCRYPT_KEY_DATA_BLOB_HEADER *header; BCRYPT_KEY_DATA_BLOB_HEADER *header;
unsigned char *pbKeyObject, *pbIV, *key, *pbCtr, *pbIVCopy; unsigned char *pbKeyObject, *pbIV, *key, *pbCtr, *pbIVCopy;
unsigned long dwKeyObject, dwIV, dwCtrLength, dwBlockLength, cbData, keylen; unsigned long dwKeyObject, dwIV, dwCtrLength, dwBlockLength,
cbData, keylen;
int ret; int ret;
(void)encrypt; (void)encrypt;
@@ -1770,14 +1793,16 @@ _libssh2_wincng_cipher_crypt(_libssh2_cipher_ctx *ctx,
if(type.ctrMode) { if(type.ctrMode) {
pbInput = ctx->pbCtr; pbInput = ctx->pbCtr;
} else { }
else {
pbInput = block; pbInput = block;
} }
if(encrypt || type.ctrMode) { if(encrypt || type.ctrMode) {
ret = BCryptEncrypt(ctx->hKey, pbInput, cbInput, NULL, ret = BCryptEncrypt(ctx->hKey, pbInput, cbInput, NULL,
ctx->pbIV, ctx->dwIV, NULL, 0, &cbOutput, 0); ctx->pbIV, ctx->dwIV, NULL, 0, &cbOutput, 0);
} else { }
else {
ret = BCryptDecrypt(ctx->hKey, pbInput, cbInput, NULL, ret = BCryptDecrypt(ctx->hKey, pbInput, cbInput, NULL,
ctx->pbIV, ctx->dwIV, NULL, 0, &cbOutput, 0); ctx->pbIV, ctx->dwIV, NULL, 0, &cbOutput, 0);
} }
@@ -1788,7 +1813,8 @@ _libssh2_wincng_cipher_crypt(_libssh2_cipher_ctx *ctx,
ret = BCryptEncrypt(ctx->hKey, pbInput, cbInput, NULL, ret = BCryptEncrypt(ctx->hKey, pbInput, cbInput, NULL,
ctx->pbIV, ctx->dwIV, ctx->pbIV, ctx->dwIV,
pbOutput, cbOutput, &cbOutput, 0); pbOutput, cbOutput, &cbOutput, 0);
} else { }
else {
ret = BCryptDecrypt(ctx->hKey, pbInput, cbInput, NULL, ret = BCryptDecrypt(ctx->hKey, pbInput, cbInput, NULL,
ctx->pbIV, ctx->dwIV, ctx->pbIV, ctx->dwIV,
pbOutput, cbOutput, &cbOutput, 0); pbOutput, cbOutput, &cbOutput, 0);
@@ -1797,13 +1823,15 @@ _libssh2_wincng_cipher_crypt(_libssh2_cipher_ctx *ctx,
if(type.ctrMode) { if(type.ctrMode) {
_libssh2_xor_data(block, block, pbOutput, blocklen); _libssh2_xor_data(block, block, pbOutput, blocklen);
_libssh2_aes_ctr_increment(ctx->pbCtr, ctx->dwCtrLength); _libssh2_aes_ctr_increment(ctx->pbCtr, ctx->dwCtrLength);
} else { }
else {
memcpy(block, pbOutput, cbOutput); memcpy(block, pbOutput, cbOutput);
} }
} }
_libssh2_wincng_safe_free(pbOutput, cbOutput); _libssh2_wincng_safe_free(pbOutput, cbOutput);
} else }
else
ret = STATUS_NO_MEMORY; ret = STATUS_NO_MEMORY;
} }
@@ -1975,9 +2003,11 @@ _libssh2_wincng_bignum_mod_exp(_libssh2_bn *r,
if(BCRYPT_SUCCESS(ret)) { if(BCRYPT_SUCCESS(ret)) {
_libssh2_wincng_bignum_resize(r, offset); _libssh2_wincng_bignum_resize(r, offset);
} }
} else }
else
ret = STATUS_NO_MEMORY; ret = STATUS_NO_MEMORY;
} else }
else
ret = STATUS_NO_MEMORY; ret = STATUS_NO_MEMORY;
} }