1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

Fix implicit type conversions and warnings on windows builds

The visual studio windows builds spit dozens of lines of warnings
on these.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2024-12-05 08:55:33 +01:00
parent a15c977cdc
commit b7018c17c7
28 changed files with 178 additions and 119 deletions

View File

@ -333,7 +333,7 @@ int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen);
/* match.c */
int match_pattern_list(const char *string, const char *pattern,
size_t len, int dolower);
int match_hostname(const char *host, const char *pattern, unsigned int len);
int match_hostname(const char *host, const char *pattern, size_t len);
#ifndef _WIN32
int match_cidr_address_list(const char *address,
const char *addrlist,

View File

@ -499,6 +499,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
unsigned int type = 0;
unsigned int flags = 0;
uint32_t dlen;
size_t request_len;
int rc;
request = ssh_buffer_new();
@ -524,10 +525,12 @@ ssh_string ssh_agent_sign_data(ssh_session session,
* - 2 x uint32_t
* - 1 x ssh_string (uint8_t + data)
*/
rc = ssh_buffer_allocate_size(request,
sizeof(uint8_t) * 2 +
sizeof(uint32_t) * 2 +
ssh_string_len(key_blob));
request_len = sizeof(uint8_t) * 2 +
sizeof(uint32_t) * 2 +
ssh_string_len(key_blob);
/* this can't overflow the uint32_t as the
* STRING_SIZE_MAX is (UINT32_MAX >> 8) + 1 */
rc = ssh_buffer_allocate_size(request, (uint32_t)request_len);
if (rc < 0) {
SSH_BUFFER_FREE(request);
return NULL;

View File

@ -183,7 +183,7 @@ error:
static int to_block4(unsigned long *block, const char *source, int num)
{
const char *ptr = NULL;
unsigned int i;
size_t i;
*block = 0;
if (num < 1) {

View File

@ -74,7 +74,7 @@ bignum ssh_make_string_bn(ssh_string string)
len * 8, len);
#endif /* DEBUG_CRYPTO */
bignum_bin2bn(string->data, len, &bn);
bignum_bin2bn(string->data, (int)len, &bn);
return bn;
}

View File

@ -669,7 +669,8 @@ int ssh_bind_config_parse_string(ssh_bind bind, const char *input)
{
char line[MAX_LINE_SIZE] = {0};
const char *c = input, *line_start = input;
unsigned int line_num = 0, line_len;
unsigned int line_num = 0;
size_t line_len;
uint32_t parser_flags;
int rv;
@ -698,8 +699,10 @@ int ssh_bind_config_parse_string(ssh_bind bind, const char *input)
}
line_len = c - line_start;
if (line_len > MAX_LINE_SIZE - 1) {
SSH_LOG(SSH_LOG_WARN, "Line %u too long: %u characters",
line_num, line_len);
SSH_LOG(SSH_LOG_WARN,
"Line %u too long: %zu characters",
line_num,
line_len);
return SSH_ERROR;
}
memcpy(line, line_start, line_len);

View File

@ -406,20 +406,26 @@ void *ssh_buffer_allocate(struct ssh_buffer_struct *buffer, uint32_t len)
*
* @return 0 on success, < 0 on error.
*/
int ssh_buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
struct ssh_string_struct *string) {
uint32_t len = 0;
int
ssh_buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
struct ssh_string_struct *string)
{
size_t len;
int rc;
if (string == NULL) {
return -1;
}
if (string == NULL) {
return -1;
}
len = ssh_string_len(string);
if (ssh_buffer_add_data(buffer, string, len + sizeof(uint32_t)) < 0) {
return -1;
}
len = ssh_string_len(string) + sizeof(uint32_t);
/* this can't overflow the uint32_t as the
* STRING_SIZE_MAX is (UINT32_MAX >> 8) + 1 */
rc = ssh_buffer_add_data(buffer, string, (uint32_t)len);
if (rc < 0) {
return -1;
}
return 0;
return 0;
}
/**
@ -978,19 +984,28 @@ ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
case 's':
cstring = va_arg(ap, char *);
len = strlen(cstring);
rc = ssh_buffer_add_u32(buffer, htonl(len));
if (len > UINT32_MAX) {
rc = SSH_ERROR;
break;
}
o.dword = (uint32_t)len;
rc = ssh_buffer_add_u32(buffer, htonl(o.dword));
if (rc == SSH_OK){
rc = ssh_buffer_add_data(buffer, cstring, len);
rc = ssh_buffer_add_data(buffer, cstring, o.dword);
}
cstring = NULL;
break;
case 'P':
len = va_arg(ap, size_t);
if (len > UINT32_MAX) {
rc = SSH_ERROR;
break;
}
o.data = va_arg(ap, void *);
count++; /* increase argument count */
rc = ssh_buffer_add_data(buffer, o.data, len);
rc = ssh_buffer_add_data(buffer, o.data, (uint32_t)len);
o.data = NULL;
break;
case 'B':
@ -1006,7 +1021,11 @@ ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
case 't':
cstring = va_arg(ap, char *);
len = strlen(cstring);
rc = ssh_buffer_add_data(buffer, cstring, len);
if (len > UINT32_MAX) {
rc = SSH_ERROR;
break;
}
rc = ssh_buffer_add_data(buffer, cstring, (uint32_t)len);
cstring = NULL;
break;
default:
@ -1186,28 +1205,28 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
if (rlen != 4){
break;
}
len = ntohl(u32len);
if (len > max_len - 1) {
u32len = ntohl(u32len);
if (u32len > max_len - 1) {
break;
}
rc = ssh_buffer_validate_length(buffer, len);
rc = ssh_buffer_validate_length(buffer, u32len);
if (rc != SSH_OK) {
break;
}
*o.cstring = malloc(len + 1);
*o.cstring = malloc(u32len + 1);
if (*o.cstring == NULL){
rc = SSH_ERROR;
break;
}
rlen = ssh_buffer_get_data(buffer, *o.cstring, len);
if (rlen != len){
rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
if (rlen != u32len) {
SAFE_FREE(*o.cstring);
rc = SSH_ERROR;
break;
}
(*o.cstring)[len] = '\0';
(*o.cstring)[u32len] = '\0';
o.cstring = NULL;
rc = SSH_OK;
break;
@ -1232,7 +1251,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
rc = SSH_ERROR;
break;
}
rlen = ssh_buffer_get_data(buffer, *o.data, len);
rlen = ssh_buffer_get_data(buffer, *o.data, (uint32_t)len);
if (rlen != len){
SAFE_FREE(*o.data);
rc = SSH_ERROR;

View File

@ -618,7 +618,8 @@ SSH_PACKET_CALLBACK(channel_rcv_data)
return SSH_PACKET_USED;
}
len = ssh_string_len(str);
/* STRING_SIZE_MAX < UINT32_MAX */
len = (uint32_t)ssh_string_len(str);
SSH_LOG(SSH_LOG_PACKET,
"Channel receiving %" PRIu32 " bytes data%s (local win=%" PRIu32
@ -1523,7 +1524,7 @@ static int channel_write_common(ssh_channel channel,
{
ssh_session session;
uint32_t origlen = len;
size_t effectivelen;
uint32_t effectivelen;
int rc;
if(channel == NULL) {
@ -1633,7 +1634,8 @@ static int channel_write_common(ssh_channel channel,
}
SSH_LOG(SSH_LOG_PACKET,
"ssh_channel_write wrote %ld bytes", (long int) effectivelen);
"ssh_channel_write wrote %" PRIu32 " bytes",
effectivelen);
channel->remote_window -= effectivelen;
len -= effectivelen;

View File

@ -226,7 +226,7 @@ int ssh_send_banner(ssh_session session, int server)
terminator);
}
rc = ssh_socket_write(session->socket, buffer, strlen(buffer));
rc = ssh_socket_write(session->socket, buffer, (uint32_t)strlen(buffer));
if (rc == SSH_ERROR) {
goto end;
}
@ -235,8 +235,8 @@ int ssh_send_banner(ssh_session session, int server)
ssh_pcap_context_write(session->pcap_ctx,
SSH_PCAP_DIR_OUT,
buffer,
strlen(buffer),
strlen(buffer));
(uint32_t)strlen(buffer),
(uint32_t)strlen(buffer));
}
#endif

View File

@ -1502,7 +1502,8 @@ int ssh_config_parse_string(ssh_session session, const char *input)
{
char line[MAX_LINE_SIZE] = {0};
const char *c = input, *line_start = input;
unsigned int line_num = 0, line_len;
unsigned int line_num = 0;
size_t line_len;
int parsing, rv;
SSH_LOG(SSH_LOG_DEBUG, "Reading configuration data from string:");
@ -1524,8 +1525,10 @@ int ssh_config_parse_string(ssh_session session, const char *input)
}
line_len = c - line_start;
if (line_len > MAX_LINE_SIZE - 1) {
SSH_LOG(SSH_LOG_TRACE, "Line %u too long: %u characters",
line_num, line_len);
SSH_LOG(SSH_LOG_TRACE,
"Line %u too long: %zu characters",
line_num,
line_len);
return SSH_ERROR;
}
memcpy(line, line_start, line_len);

View File

@ -209,7 +209,8 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
bind_itr != NULL;
bind_itr = bind_itr->ai_next)
{
if (bind(s, bind_itr->ai_addr, bind_itr->ai_addrlen) < 0) {
rc = bind(s, bind_itr->ai_addr, bind_itr->ai_addrlen);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL,
"Binding local address: %s",
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));

View File

@ -264,17 +264,17 @@ static void ssh_connector_fd_in_cb(ssh_connector connector)
}
connector->in_available = 1; /* Don't poll on it */
return;
} else if (r> 0) {
} else if (r > 0) {
/* loop around ssh_channel_write in case our window reduced due to a race */
while (total != r){
if (connector->out_flags & SSH_CONNECTOR_STDOUT) {
w = ssh_channel_write(connector->out_channel,
buffer + total,
r - total);
(uint32_t)(r - total));
} else {
w = ssh_channel_write_stderr(connector->out_channel,
buffer + total,
r - total);
(uint32_t)(r - total));
}
if (w == SSH_ERROR) {
return;
@ -294,7 +294,7 @@ static void ssh_connector_fd_in_cb(ssh_connector connector)
while (total < r) {
w = ssh_connector_fd_write(connector,
buffer + total,
r - total);
(uint32_t)(r - total));
if (w < 0) {
ssh_connector_except(connector, connector->out_fd);
return;
@ -340,8 +340,9 @@ ssh_connector_fd_out_cb(ssh_connector connector)
} else if (r > 0) {
/* loop around write in case the write blocks even for CHUNKSIZE bytes */
while (total != r) {
w = ssh_connector_fd_write(connector, buffer + total,
r - total);
w = ssh_connector_fd_write(connector,
buffer + total,
(uint32_t)(r - total));
if (w < 0) {
ssh_connector_except(connector, connector->out_fd);
return;
@ -476,9 +477,11 @@ static int ssh_connector_channel_data_cb(ssh_session session,
ssh_connector_except_channel(connector, connector->out_channel);
}
} else if (connector->out_fd != SSH_INVALID_SOCKET) {
w = ssh_connector_fd_write(connector, data, len);
if (w < 0)
ssize_t ws = ssh_connector_fd_write(connector, data, len);
if (ws < 0) {
ssh_connector_except(connector, connector->out_fd);
}
w = (int)ws;
} else {
ssh_set_error(session, SSH_FATAL, "output socket or channel closed");
return SSH_ERROR;

View File

@ -592,7 +592,7 @@ int ssh_dh_compute_shared_secret(struct dh_ctx *dh_ctx, int local, int remote,
}
#endif /* OPENSSL_VERSION_NUMBER */
*dest = BN_bin2bn(kstring, klen, NULL);
*dest = BN_bin2bn(kstring, (int)klen, NULL);
if (*dest == NULL) {
rc = SSH_ERROR;
goto done;

View File

@ -63,7 +63,7 @@ static int ssh_gets(const char *prompt, char *buf, size_t len, int verify)
fprintf(stdout, "%s", prompt);
}
fflush(stdout);
if (fgets(tmp, len, stdin) == NULL) {
if (fgets(tmp, (int)len, stdin) == NULL) {
free(tmp);
return 0;
}
@ -87,7 +87,7 @@ static int ssh_gets(const char *prompt, char *buf, size_t len, int verify)
fprintf(stdout, "\nVerifying, please re-enter. %s", prompt);
fflush(stdout);
if (! fgets(key_string, len, stdin)) {
if (!fgets(key_string, (int)len, stdin)) {
explicit_bzero(key_string, len);
SAFE_FREE(key_string);
clearerr(stdin);

View File

@ -171,7 +171,7 @@ static int known_hosts_read_line(FILE *fp,
size_t *buf_len,
size_t *lineno)
{
while (fgets(buf, buf_size, fp) != NULL) {
while (fgets(buf, (int)buf_size, fp) != NULL) {
size_t len;
if (buf[0] == '\0') {
continue;

View File

@ -312,7 +312,7 @@ HMACCTX hmac_init(const void *key, size_t len, enum ssh_hmac_e type)
return NULL;
}
pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, len);
pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, (int)len);
if (pkey == NULL) {
goto error;
}
@ -598,7 +598,7 @@ evp_cipher_aead_encrypt(struct ssh_cipher_struct *cipher,
(unsigned char *)out + aadlen,
&tmplen,
(unsigned char *)in + aadlen,
(int)len - aadlen);
(int)(len - aadlen));
outlen = tmplen;
if (rc != 1 || outlen != (int)len - aadlen) {
SSH_LOG(SSH_LOG_TRACE, "EVP_EncryptUpdate failed");
@ -616,7 +616,7 @@ evp_cipher_aead_encrypt(struct ssh_cipher_struct *cipher,
rc = EVP_CIPHER_CTX_ctrl(cipher->ctx,
EVP_CTRL_GCM_GET_TAG,
authlen,
(int)authlen,
(unsigned char *)tag);
if (rc != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CTRL_GCM_GET_TAG failed");
@ -654,7 +654,7 @@ evp_cipher_aead_decrypt(struct ssh_cipher_struct *cipher,
/* set tag for authentication */
rc = EVP_CIPHER_CTX_ctrl(cipher->ctx,
EVP_CTRL_GCM_SET_TAG,
authlen,
(int)authlen,
(unsigned char *)complete_packet + aadlen + encrypted_size);
if (rc == 0) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CTRL_GCM_SET_TAG failed");
@ -679,7 +679,7 @@ evp_cipher_aead_decrypt(struct ssh_cipher_struct *cipher,
(unsigned char *)out,
&outlen,
(unsigned char *)complete_packet + aadlen,
encrypted_size /* already subtracted aadlen */);
(int)encrypted_size /* already subtracted aadlen */);
if (rc != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_DecryptUpdate failed");
return SSH_ERROR;
@ -961,7 +961,7 @@ chacha20_poly1305_aead_decrypt_length(struct ssh_cipher_struct *cipher,
return SSH_ERROR;
}
rv = EVP_CipherUpdate(ctx->header_evp, out, &outlen, in, len);
rv = EVP_CipherUpdate(ctx->header_evp, out, &outlen, in, (int)len);
if (rv != 1 || outlen != sizeof(uint32_t)) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed");
return SSH_ERROR;
@ -1048,9 +1048,11 @@ chacha20_poly1305_aead_decrypt(struct ssh_cipher_struct *cipher,
}
/* Decrypt the message */
rv = EVP_CipherUpdate(ctx->main_evp, out, &len,
rv = EVP_CipherUpdate(ctx->main_evp,
out,
&len,
(uint8_t *)complete_packet + sizeof(uint32_t),
encrypted_size);
(int)encrypted_size);
if (rv != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed");
goto out;
@ -1117,7 +1119,7 @@ chacha20_poly1305_aead_encrypt(struct ssh_cipher_struct *cipher,
out_packet->payload,
&outlen,
in_packet->payload,
len - sizeof(uint32_t));
(int)(len - sizeof(uint32_t)));
if (ret != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed");
return;

View File

@ -205,8 +205,10 @@ int match_pattern_list(const char *string, const char *pattern,
* Returns -1 if negation matches, 1 if there is a positive match, 0 if there
* is no match at all.
*/
int match_hostname(const char *host, const char *pattern, unsigned int len) {
return match_pattern_list(host, pattern, len, 1);
int
match_hostname(const char *host, const char *pattern, size_t len)
{
return match_pattern_list(host, pattern, len, 1);
}
#ifndef _WIN32

View File

@ -1829,7 +1829,7 @@ int ssh_quote_file_name(const char *file_name, char *buf, size_t buf_len)
/* Put the string terminator */
*dst = '\0';
return dst - buf;
return (int)(dst - buf);
error:
return SSH_ERROR;
@ -1875,7 +1875,7 @@ int ssh_newline_vis(const char *string, char *buf, size_t buf_len)
}
*out = '\0';
return out - buf;
return (int)(out - buf);
}
/**

View File

@ -1068,7 +1068,7 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
uint32_t lenfield_blocksize = 8;
size_t current_macsize = 0;
uint8_t *ptr = NULL;
long to_be_read;
ssize_t to_be_read;
int rc;
uint8_t *cleartext_packet = NULL;
uint8_t *packet_second_block = NULL;
@ -1178,7 +1178,7 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
/* remote sshd sends invalid sizes? */
ssh_set_error(session,
SSH_FATAL,
"Given numbers of bytes left to be read < 0 (%ld)!",
"Given numbers of bytes left to be read < 0 (%zd)!",
to_be_read);
goto error;
}
@ -1196,7 +1196,7 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
/* give up, not enough data in buffer */
SSH_LOG(SSH_LOG_PACKET,
"packet: partial packet (read len) "
"[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%ld]",
"[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
packet_len,
receivedlen,
to_be_read);
@ -1210,7 +1210,7 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
/* remaining encrypted bytes from the packet, MAC not included */
packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
cleartext_packet = ssh_buffer_allocate(session->in_buffer,
packet_remaining);
(uint32_t)packet_remaining);
if (cleartext_packet == NULL) {
goto error;
}
@ -1388,6 +1388,7 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
session->packet_state = PACKET_STATE_INIT;
if (processed < receivedlen) {
size_t num;
/* Handle a potential packet left in socket buffer */
SSH_LOG(SSH_LOG_PACKET,
"Processing %zu bytes left in socket buffer",
@ -1395,9 +1396,10 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
ptr = ((uint8_t*)data) + processed;
rc = ssh_packet_socket_callback(ptr, receivedlen - processed,
user);
processed += rc;
num = ssh_packet_socket_callback(ptr,
receivedlen - processed,
user);
processed += num;
}
ok = ssh_packet_need_rekey(session, 0);
@ -1768,7 +1770,7 @@ static int packet_send2(ssh_session session)
if (hmac != NULL) {
rc = ssh_buffer_add_data(session->out_buffer,
hmac,
hmac_digest_len(hmac_type));
(uint32_t)hmac_digest_len(hmac_type));
if (rc < 0) {
goto error;
}

View File

@ -1699,8 +1699,9 @@ int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
return SSH_ERROR;
}
rc = ssh_buffer_add_data(buffer, ssh_string_data(key_blob),
ssh_string_len(key_blob));
rc = ssh_buffer_add_data(buffer,
ssh_string_data(key_blob),
(uint32_t)ssh_string_len(key_blob));
if (rc < 0) {
SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
goto fail;
@ -2433,7 +2434,7 @@ int ssh_pki_import_signature_blob(const ssh_string sig_blob,
rc = ssh_buffer_add_data(buf,
ssh_string_data(sig_blob),
ssh_string_len(sig_blob));
(uint32_t)ssh_string_len(sig_blob));
if (rc < 0) {
SSH_BUFFER_FREE(buf);
return SSH_ERROR;

View File

@ -155,7 +155,7 @@ static int pki_private_key_decrypt(ssh_string blob,
}
rc = ssh_buffer_add_data(buffer,
ssh_string_data(kdfoptions),
ssh_string_len(kdfoptions));
(uint32_t)ssh_string_len(kdfoptions));
if (rc != SSH_ERROR){
rc = ssh_buffer_unpack(buffer, "Sd", &salt, &rounds);
}
@ -339,7 +339,7 @@ ssh_pki_openssh_import(const char *text_key,
ssh_buffer_set_secure(privkey_buffer);
ssh_buffer_add_data(privkey_buffer,
ssh_string_data(privkeys),
ssh_string_len(privkeys));
(uint32_t)ssh_string_len(privkeys));
rc = ssh_buffer_unpack(privkey_buffer, "dd", &checkint1, &checkint2);
if (rc == SSH_ERROR || checkint1 != checkint2) {

View File

@ -86,7 +86,7 @@ static int pem_get_password(char *buf, int size, int rwflag, void *userdata) {
buf, size, 0, 0,
pgp->data);
if (rc == 0) {
return strlen(buf);
return (int)strlen(buf);
}
}
@ -1869,7 +1869,7 @@ static ssh_string pki_ecdsa_signature_to_blob(const ssh_signature sig)
const BIGNUM *pr = NULL, *ps = NULL;
const unsigned char *raw_sig_data = NULL;
size_t raw_sig_len;
long raw_sig_len;
ECDSA_SIG *ecdsa_sig;
@ -1882,7 +1882,7 @@ static ssh_string pki_ecdsa_signature_to_blob(const ssh_signature sig)
if (raw_sig_data == NULL) {
return NULL;
}
raw_sig_len = ssh_string_len(sig->raw_sig);
raw_sig_len = (long)ssh_string_len(sig->raw_sig);
ecdsa_sig = d2i_ECDSA_SIG(NULL, &raw_sig_data, raw_sig_len);
if (ecdsa_sig == NULL) {
@ -1977,7 +1977,7 @@ static int pki_signature_from_rsa_blob(const ssh_key pubkey,
const ssh_string sig_blob,
ssh_signature sig)
{
uint32_t pad_len = 0;
size_t pad_len = 0;
char *blob_orig = NULL;
char *blob_padded_data = NULL;
ssh_string sig_blob_padded = NULL;
@ -2080,7 +2080,7 @@ static int pki_signature_from_ecdsa_blob(UNUSED_PARAM(const ssh_key pubkey),
rc = ssh_buffer_add_data(buf,
ssh_string_data(sig_blob),
ssh_string_len(sig_blob));
(uint32_t)ssh_string_len(sig_blob));
if (rc < 0) {
goto error;
}
@ -2511,7 +2511,7 @@ int pki_verify_data_signature(ssh_signature signature,
EVP_PKEY *pkey = NULL;
unsigned char *raw_sig_data = NULL;
unsigned int raw_sig_len;
size_t raw_sig_len;
/* Function return code
* Do not change this variable throughout the function until the signature

View File

@ -482,8 +482,8 @@ static size_t callback_receive_banner(const void *data, size_t len, void *user)
ssh_pcap_context_write(session->pcap_ctx,
SSH_PCAP_DIR_IN,
buffer,
i + 1,
i + 1);
(uint32_t)(i + 1),
(uint32_t)(i + 1));
}
#endif
if (buffer[i] == '\r') {

View File

@ -605,27 +605,30 @@ const char *sftp_extensions_get_data(sftp_session sftp, unsigned int idx) {
return sftp->ext->data[idx];
}
int sftp_extension_supported(sftp_session sftp, const char *name,
const char *data) {
size_t i, n;
int
sftp_extension_supported(sftp_session sftp,
const char *name,
const char *data)
{
unsigned int i, n;
if (sftp == NULL || name == NULL || data == NULL) {
return 0;
}
n = sftp_extensions_get_count(sftp);
for (i = 0; i < n; i++) {
const char *ext_name = sftp_extensions_get_name(sftp, i);
const char *ext_data = sftp_extensions_get_data(sftp, i);
if (ext_name != NULL && ext_data != NULL &&
strcmp(ext_name, name) == 0 &&
strcmp(ext_data, data) == 0) {
return 1;
if (sftp == NULL || name == NULL || data == NULL) {
return 0;
}
}
return 0;
n = sftp_extensions_get_count(sftp);
for (i = 0; i < n; i++) {
const char *ext_name = sftp_extensions_get_name(sftp, i);
const char *ext_data = sftp_extensions_get_data(sftp, i);
if (ext_name != NULL && ext_data != NULL &&
strcmp(ext_name, name) == 0 &&
strcmp(ext_data, data) == 0) {
return 1;
}
}
return 0;
}
static sftp_file parse_handle_msg(sftp_message msg){
@ -1156,7 +1159,10 @@ ssize_t sftp_read(sftp_file handle, void *buf, size_t count) {
* requested to provide less surprises to the calling applications.
*/
if (count > sftp->limits->max_read_length) {
count = sftp->limits->max_read_length;
if (sftp->limits->max_read_length > SIZE_MAX) {
return SSH_ERROR;
}
count = (size_t)sftp->limits->max_read_length;
}
buffer = ssh_buffer_new();
@ -1297,7 +1303,7 @@ int sftp_async_read(sftp_file file, void *data, uint32_t size, uint32_t id){
sftp_status_message status;
ssh_string datastring;
int rc, err = SSH_OK;
uint32_t len;
size_t len;
if (file == NULL) {
return SSH_ERROR;
@ -1352,7 +1358,7 @@ int sftp_async_read(sftp_file file, void *data, uint32_t size, uint32_t id){
file->offset = file->offset - (size - len);
memcpy(data, ssh_string_data(datastring), len);
SSH_STRING_FREE(datastring);
return len;
return (int)len;
default:
ssh_set_error(sftp->session,SSH_FATAL,"Received message %d during read!",msg->packet_type);
sftp_message_free(msg);
@ -1396,7 +1402,10 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
* requested to provide less surprises to the calling applications.
*/
if (count > sftp->limits->max_write_length) {
count = sftp->limits->max_write_length;
if (sftp->limits->max_write_length > SIZE_MAX) {
return SSH_ERROR;
}
count = (size_t)sftp->limits->max_write_length;
}
rc = ssh_buffer_pack(buffer,

View File

@ -75,7 +75,10 @@ ssize_t sftp_aio_begin_read(sftp_file file, size_t len, sftp_aio *aio)
/* Apply a cap on the length a user is allowed to read */
if (len > sftp->limits->max_read_length) {
len = sftp->limits->max_read_length;
if (sftp->limits->max_read_length > SIZE_MAX) {
return SSH_ERROR;
}
len = (size_t)sftp->limits->max_read_length;
}
if (aio == NULL) {
@ -337,7 +340,10 @@ ssize_t sftp_aio_begin_write(sftp_file file,
/* Apply a cap on the length a user is allowed to write */
if (len > sftp->limits->max_write_length) {
len = sftp->limits->max_write_length;
if (sftp->limits->max_write_length > SIZE_MAX) {
return SSH_ERROR;
}
len = (size_t)sftp->limits->max_write_length;
}
if (aio == NULL) {

View File

@ -787,8 +787,8 @@ stat_to_filexfer_attrib(const struct stat *z_st, struct sftp_attributes_struct *
z_attr->permissions = z_st->st_mode;
z_attr->flags |= (uint32_t)SSH_FILEXFER_ATTR_ACMODTIME;
z_attr->atime = z_st->st_atime;
z_attr->mtime = z_st->st_mtime;
z_attr->atime = (uint32_t)z_st->st_atime;
z_attr->mtime = (uint32_t)z_st->st_mtime;
}
static void

View File

@ -312,7 +312,8 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p,
}
/* Rollback the unused space */
ssh_buffer_pass_bytes_end(s->in_buffer, MAX_BUF_SIZE - nread);
ssh_buffer_pass_bytes_end(s->in_buffer,
(uint32_t)(MAX_BUF_SIZE - nread));
if (nread == 0) {
if (p != NULL) {
@ -337,7 +338,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p,
processed = s->callbacks->data(ssh_buffer_get(s->in_buffer),
ssh_buffer_get_len(s->in_buffer),
s->callbacks->userdata);
ssh_buffer_pass_bytes(s->in_buffer, processed);
ssh_buffer_pass_bytes(s->in_buffer, (uint32_t)processed);
} while ((processed > 0) && (s->state == SSH_SOCKET_CONNECTED));
/* p may have been freed, so don't use it
@ -742,7 +743,7 @@ int ssh_socket_nonblocking_flush(ssh_socket s)
return SSH_ERROR;
}
ssh_buffer_pass_bytes(s->out_buffer, bwritten);
ssh_buffer_pass_bytes(s->out_buffer, (uint32_t)bwritten);
if (s->session->socket_counter != NULL) {
s->session->socket_counter->out_bytes += bwritten;
}

View File

@ -67,7 +67,7 @@ struct ssh_string_struct *ssh_string_new(size_t size)
return NULL;
}
str->size = htonl(size);
str->size = htonl((uint32_t)size);
str->data[0] = 0;
return str;

View File

@ -1453,6 +1453,8 @@ static void torture_options_getopt(void **state)
/* Test with all the supported options */
rc = ssh_options_getopt(session, &argc, (char **)argv);
#ifdef _MSC_VER
UNUSED_VAR(new_level);
/* Not supported in windows */
assert_ssh_return_code_equal(session, rc, -1);
#else