1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-31 00:03:07 +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 */ /* match.c */
int match_pattern_list(const char *string, const char *pattern, int match_pattern_list(const char *string, const char *pattern,
size_t len, int dolower); 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 #ifndef _WIN32
int match_cidr_address_list(const char *address, int match_cidr_address_list(const char *address,
const char *addrlist, const char *addrlist,

View File

@ -499,6 +499,7 @@ ssh_string ssh_agent_sign_data(ssh_session session,
unsigned int type = 0; unsigned int type = 0;
unsigned int flags = 0; unsigned int flags = 0;
uint32_t dlen; uint32_t dlen;
size_t request_len;
int rc; int rc;
request = ssh_buffer_new(); request = ssh_buffer_new();
@ -524,10 +525,12 @@ ssh_string ssh_agent_sign_data(ssh_session session,
* - 2 x uint32_t * - 2 x uint32_t
* - 1 x ssh_string (uint8_t + data) * - 1 x ssh_string (uint8_t + data)
*/ */
rc = ssh_buffer_allocate_size(request, request_len = sizeof(uint8_t) * 2 +
sizeof(uint8_t) * 2 + sizeof(uint32_t) * 2 +
sizeof(uint32_t) * 2 + ssh_string_len(key_blob);
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) { if (rc < 0) {
SSH_BUFFER_FREE(request); SSH_BUFFER_FREE(request);
return NULL; return NULL;

View File

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

View File

@ -74,7 +74,7 @@ bignum ssh_make_string_bn(ssh_string string)
len * 8, len); len * 8, len);
#endif /* DEBUG_CRYPTO */ #endif /* DEBUG_CRYPTO */
bignum_bin2bn(string->data, len, &bn); bignum_bin2bn(string->data, (int)len, &bn);
return 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}; char line[MAX_LINE_SIZE] = {0};
const char *c = input, *line_start = input; 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; uint32_t parser_flags;
int rv; int rv;
@ -698,8 +699,10 @@ int ssh_bind_config_parse_string(ssh_bind bind, const char *input)
} }
line_len = c - line_start; line_len = c - line_start;
if (line_len > MAX_LINE_SIZE - 1) { if (line_len > MAX_LINE_SIZE - 1) {
SSH_LOG(SSH_LOG_WARN, "Line %u too long: %u characters", SSH_LOG(SSH_LOG_WARN,
line_num, line_len); "Line %u too long: %zu characters",
line_num,
line_len);
return SSH_ERROR; return SSH_ERROR;
} }
memcpy(line, line_start, line_len); 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. * @return 0 on success, < 0 on error.
*/ */
int ssh_buffer_add_ssh_string(struct ssh_buffer_struct *buffer, int
struct ssh_string_struct *string) { ssh_buffer_add_ssh_string(struct ssh_buffer_struct *buffer,
uint32_t len = 0; struct ssh_string_struct *string)
{
size_t len;
int rc;
if (string == NULL) { if (string == NULL) {
return -1; return -1;
} }
len = ssh_string_len(string); len = ssh_string_len(string) + sizeof(uint32_t);
if (ssh_buffer_add_data(buffer, string, len + sizeof(uint32_t)) < 0) { /* this can't overflow the uint32_t as the
return -1; * 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': case 's':
cstring = va_arg(ap, char *); cstring = va_arg(ap, char *);
len = strlen(cstring); 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){ if (rc == SSH_OK){
rc = ssh_buffer_add_data(buffer, cstring, len); rc = ssh_buffer_add_data(buffer, cstring, o.dword);
} }
cstring = NULL; cstring = NULL;
break; break;
case 'P': case 'P':
len = va_arg(ap, size_t); len = va_arg(ap, size_t);
if (len > UINT32_MAX) {
rc = SSH_ERROR;
break;
}
o.data = va_arg(ap, void *); o.data = va_arg(ap, void *);
count++; /* increase argument count */ 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; o.data = NULL;
break; break;
case 'B': case 'B':
@ -1006,7 +1021,11 @@ ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
case 't': case 't':
cstring = va_arg(ap, char *); cstring = va_arg(ap, char *);
len = strlen(cstring); 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; cstring = NULL;
break; break;
default: default:
@ -1186,28 +1205,28 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
if (rlen != 4){ if (rlen != 4){
break; break;
} }
len = ntohl(u32len); u32len = ntohl(u32len);
if (len > max_len - 1) { if (u32len > max_len - 1) {
break; break;
} }
rc = ssh_buffer_validate_length(buffer, len); rc = ssh_buffer_validate_length(buffer, u32len);
if (rc != SSH_OK) { if (rc != SSH_OK) {
break; break;
} }
*o.cstring = malloc(len + 1); *o.cstring = malloc(u32len + 1);
if (*o.cstring == NULL){ if (*o.cstring == NULL){
rc = SSH_ERROR; rc = SSH_ERROR;
break; break;
} }
rlen = ssh_buffer_get_data(buffer, *o.cstring, len); rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
if (rlen != len){ if (rlen != u32len) {
SAFE_FREE(*o.cstring); SAFE_FREE(*o.cstring);
rc = SSH_ERROR; rc = SSH_ERROR;
break; break;
} }
(*o.cstring)[len] = '\0'; (*o.cstring)[u32len] = '\0';
o.cstring = NULL; o.cstring = NULL;
rc = SSH_OK; rc = SSH_OK;
break; break;
@ -1232,7 +1251,7 @@ int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
rc = SSH_ERROR; rc = SSH_ERROR;
break; break;
} }
rlen = ssh_buffer_get_data(buffer, *o.data, len); rlen = ssh_buffer_get_data(buffer, *o.data, (uint32_t)len);
if (rlen != len){ if (rlen != len){
SAFE_FREE(*o.data); SAFE_FREE(*o.data);
rc = SSH_ERROR; rc = SSH_ERROR;

View File

@ -618,7 +618,8 @@ SSH_PACKET_CALLBACK(channel_rcv_data)
return SSH_PACKET_USED; 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, SSH_LOG(SSH_LOG_PACKET,
"Channel receiving %" PRIu32 " bytes data%s (local win=%" PRIu32 "Channel receiving %" PRIu32 " bytes data%s (local win=%" PRIu32
@ -1523,7 +1524,7 @@ static int channel_write_common(ssh_channel channel,
{ {
ssh_session session; ssh_session session;
uint32_t origlen = len; uint32_t origlen = len;
size_t effectivelen; uint32_t effectivelen;
int rc; int rc;
if(channel == NULL) { if(channel == NULL) {
@ -1633,7 +1634,8 @@ static int channel_write_common(ssh_channel channel,
} }
SSH_LOG(SSH_LOG_PACKET, 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; channel->remote_window -= effectivelen;
len -= effectivelen; len -= effectivelen;

View File

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

View File

@ -1502,7 +1502,8 @@ int ssh_config_parse_string(ssh_session session, const char *input)
{ {
char line[MAX_LINE_SIZE] = {0}; char line[MAX_LINE_SIZE] = {0};
const char *c = input, *line_start = input; 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; int parsing, rv;
SSH_LOG(SSH_LOG_DEBUG, "Reading configuration data from string:"); 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; line_len = c - line_start;
if (line_len > MAX_LINE_SIZE - 1) { if (line_len > MAX_LINE_SIZE - 1) {
SSH_LOG(SSH_LOG_TRACE, "Line %u too long: %u characters", SSH_LOG(SSH_LOG_TRACE,
line_num, line_len); "Line %u too long: %zu characters",
line_num,
line_len);
return SSH_ERROR; return SSH_ERROR;
} }
memcpy(line, line_start, line_len); 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 != NULL;
bind_itr = bind_itr->ai_next) 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, ssh_set_error(session, SSH_FATAL,
"Binding local address: %s", "Binding local address: %s",
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX)); 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 */ connector->in_available = 1; /* Don't poll on it */
return; return;
} else if (r> 0) { } else if (r > 0) {
/* loop around ssh_channel_write in case our window reduced due to a race */ /* loop around ssh_channel_write in case our window reduced due to a race */
while (total != r){ while (total != r){
if (connector->out_flags & SSH_CONNECTOR_STDOUT) { if (connector->out_flags & SSH_CONNECTOR_STDOUT) {
w = ssh_channel_write(connector->out_channel, w = ssh_channel_write(connector->out_channel,
buffer + total, buffer + total,
r - total); (uint32_t)(r - total));
} else { } else {
w = ssh_channel_write_stderr(connector->out_channel, w = ssh_channel_write_stderr(connector->out_channel,
buffer + total, buffer + total,
r - total); (uint32_t)(r - total));
} }
if (w == SSH_ERROR) { if (w == SSH_ERROR) {
return; return;
@ -294,7 +294,7 @@ static void ssh_connector_fd_in_cb(ssh_connector connector)
while (total < r) { while (total < r) {
w = ssh_connector_fd_write(connector, w = ssh_connector_fd_write(connector,
buffer + total, buffer + total,
r - total); (uint32_t)(r - total));
if (w < 0) { if (w < 0) {
ssh_connector_except(connector, connector->out_fd); ssh_connector_except(connector, connector->out_fd);
return; return;
@ -340,8 +340,9 @@ ssh_connector_fd_out_cb(ssh_connector connector)
} else if (r > 0) { } else if (r > 0) {
/* loop around write in case the write blocks even for CHUNKSIZE bytes */ /* loop around write in case the write blocks even for CHUNKSIZE bytes */
while (total != r) { while (total != r) {
w = ssh_connector_fd_write(connector, buffer + total, w = ssh_connector_fd_write(connector,
r - total); buffer + total,
(uint32_t)(r - total));
if (w < 0) { if (w < 0) {
ssh_connector_except(connector, connector->out_fd); ssh_connector_except(connector, connector->out_fd);
return; return;
@ -476,9 +477,11 @@ static int ssh_connector_channel_data_cb(ssh_session session,
ssh_connector_except_channel(connector, connector->out_channel); ssh_connector_except_channel(connector, connector->out_channel);
} }
} else if (connector->out_fd != SSH_INVALID_SOCKET) { } else if (connector->out_fd != SSH_INVALID_SOCKET) {
w = ssh_connector_fd_write(connector, data, len); ssize_t ws = ssh_connector_fd_write(connector, data, len);
if (w < 0) if (ws < 0) {
ssh_connector_except(connector, connector->out_fd); ssh_connector_except(connector, connector->out_fd);
}
w = (int)ws;
} else { } else {
ssh_set_error(session, SSH_FATAL, "output socket or channel closed"); ssh_set_error(session, SSH_FATAL, "output socket or channel closed");
return SSH_ERROR; 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 */ #endif /* OPENSSL_VERSION_NUMBER */
*dest = BN_bin2bn(kstring, klen, NULL); *dest = BN_bin2bn(kstring, (int)klen, NULL);
if (*dest == NULL) { if (*dest == NULL) {
rc = SSH_ERROR; rc = SSH_ERROR;
goto done; 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); fprintf(stdout, "%s", prompt);
} }
fflush(stdout); fflush(stdout);
if (fgets(tmp, len, stdin) == NULL) { if (fgets(tmp, (int)len, stdin) == NULL) {
free(tmp); free(tmp);
return 0; 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); fprintf(stdout, "\nVerifying, please re-enter. %s", prompt);
fflush(stdout); fflush(stdout);
if (! fgets(key_string, len, stdin)) { if (!fgets(key_string, (int)len, stdin)) {
explicit_bzero(key_string, len); explicit_bzero(key_string, len);
SAFE_FREE(key_string); SAFE_FREE(key_string);
clearerr(stdin); clearerr(stdin);

View File

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

View File

@ -312,7 +312,7 @@ HMACCTX hmac_init(const void *key, size_t len, enum ssh_hmac_e type)
return NULL; 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) { if (pkey == NULL) {
goto error; goto error;
} }
@ -598,7 +598,7 @@ evp_cipher_aead_encrypt(struct ssh_cipher_struct *cipher,
(unsigned char *)out + aadlen, (unsigned char *)out + aadlen,
&tmplen, &tmplen,
(unsigned char *)in + aadlen, (unsigned char *)in + aadlen,
(int)len - aadlen); (int)(len - aadlen));
outlen = tmplen; outlen = tmplen;
if (rc != 1 || outlen != (int)len - aadlen) { if (rc != 1 || outlen != (int)len - aadlen) {
SSH_LOG(SSH_LOG_TRACE, "EVP_EncryptUpdate failed"); 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, rc = EVP_CIPHER_CTX_ctrl(cipher->ctx,
EVP_CTRL_GCM_GET_TAG, EVP_CTRL_GCM_GET_TAG,
authlen, (int)authlen,
(unsigned char *)tag); (unsigned char *)tag);
if (rc != 1) { if (rc != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CTRL_GCM_GET_TAG failed"); 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 */ /* set tag for authentication */
rc = EVP_CIPHER_CTX_ctrl(cipher->ctx, rc = EVP_CIPHER_CTX_ctrl(cipher->ctx,
EVP_CTRL_GCM_SET_TAG, EVP_CTRL_GCM_SET_TAG,
authlen, (int)authlen,
(unsigned char *)complete_packet + aadlen + encrypted_size); (unsigned char *)complete_packet + aadlen + encrypted_size);
if (rc == 0) { if (rc == 0) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CTRL_GCM_SET_TAG failed"); 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, (unsigned char *)out,
&outlen, &outlen,
(unsigned char *)complete_packet + aadlen, (unsigned char *)complete_packet + aadlen,
encrypted_size /* already subtracted aadlen */); (int)encrypted_size /* already subtracted aadlen */);
if (rc != 1) { if (rc != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_DecryptUpdate failed"); SSH_LOG(SSH_LOG_TRACE, "EVP_DecryptUpdate failed");
return SSH_ERROR; return SSH_ERROR;
@ -961,7 +961,7 @@ chacha20_poly1305_aead_decrypt_length(struct ssh_cipher_struct *cipher,
return SSH_ERROR; 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)) { if (rv != 1 || outlen != sizeof(uint32_t)) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed"); SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed");
return SSH_ERROR; return SSH_ERROR;
@ -1048,9 +1048,11 @@ chacha20_poly1305_aead_decrypt(struct ssh_cipher_struct *cipher,
} }
/* Decrypt the message */ /* 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), (uint8_t *)complete_packet + sizeof(uint32_t),
encrypted_size); (int)encrypted_size);
if (rv != 1) { if (rv != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed"); SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed");
goto out; goto out;
@ -1117,7 +1119,7 @@ chacha20_poly1305_aead_encrypt(struct ssh_cipher_struct *cipher,
out_packet->payload, out_packet->payload,
&outlen, &outlen,
in_packet->payload, in_packet->payload,
len - sizeof(uint32_t)); (int)(len - sizeof(uint32_t)));
if (ret != 1) { if (ret != 1) {
SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed"); SSH_LOG(SSH_LOG_TRACE, "EVP_CipherUpdate failed");
return; 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 * Returns -1 if negation matches, 1 if there is a positive match, 0 if there
* is no match at all. * is no match at all.
*/ */
int match_hostname(const char *host, const char *pattern, unsigned int len) { int
return match_pattern_list(host, pattern, len, 1); match_hostname(const char *host, const char *pattern, size_t len)
{
return match_pattern_list(host, pattern, len, 1);
} }
#ifndef _WIN32 #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 */ /* Put the string terminator */
*dst = '\0'; *dst = '\0';
return dst - buf; return (int)(dst - buf);
error: error:
return SSH_ERROR; return SSH_ERROR;
@ -1875,7 +1875,7 @@ int ssh_newline_vis(const char *string, char *buf, size_t buf_len)
} }
*out = '\0'; *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; uint32_t lenfield_blocksize = 8;
size_t current_macsize = 0; size_t current_macsize = 0;
uint8_t *ptr = NULL; uint8_t *ptr = NULL;
long to_be_read; ssize_t to_be_read;
int rc; int rc;
uint8_t *cleartext_packet = NULL; uint8_t *cleartext_packet = NULL;
uint8_t *packet_second_block = 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? */ /* remote sshd sends invalid sizes? */
ssh_set_error(session, ssh_set_error(session,
SSH_FATAL, 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); to_be_read);
goto error; 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 */ /* give up, not enough data in buffer */
SSH_LOG(SSH_LOG_PACKET, SSH_LOG(SSH_LOG_PACKET,
"packet: partial packet (read len) " "packet: partial packet (read len) "
"[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%ld]", "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
packet_len, packet_len,
receivedlen, receivedlen,
to_be_read); 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 */ /* remaining encrypted bytes from the packet, MAC not included */
packet_remaining = packet_len - (packet_offset - sizeof(uint32_t)); packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
cleartext_packet = ssh_buffer_allocate(session->in_buffer, cleartext_packet = ssh_buffer_allocate(session->in_buffer,
packet_remaining); (uint32_t)packet_remaining);
if (cleartext_packet == NULL) { if (cleartext_packet == NULL) {
goto error; goto error;
} }
@ -1388,6 +1388,7 @@ ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
session->packet_state = PACKET_STATE_INIT; session->packet_state = PACKET_STATE_INIT;
if (processed < receivedlen) { if (processed < receivedlen) {
size_t num;
/* Handle a potential packet left in socket buffer */ /* Handle a potential packet left in socket buffer */
SSH_LOG(SSH_LOG_PACKET, SSH_LOG(SSH_LOG_PACKET,
"Processing %zu bytes left in socket buffer", "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; ptr = ((uint8_t*)data) + processed;
rc = ssh_packet_socket_callback(ptr, receivedlen - processed, num = ssh_packet_socket_callback(ptr,
user); receivedlen - processed,
processed += rc; user);
processed += num;
} }
ok = ssh_packet_need_rekey(session, 0); ok = ssh_packet_need_rekey(session, 0);
@ -1768,7 +1770,7 @@ static int packet_send2(ssh_session session)
if (hmac != NULL) { if (hmac != NULL) {
rc = ssh_buffer_add_data(session->out_buffer, rc = ssh_buffer_add_data(session->out_buffer,
hmac, hmac,
hmac_digest_len(hmac_type)); (uint32_t)hmac_digest_len(hmac_type));
if (rc < 0) { if (rc < 0) {
goto error; goto error;
} }

View File

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

View File

@ -155,7 +155,7 @@ static int pki_private_key_decrypt(ssh_string blob,
} }
rc = ssh_buffer_add_data(buffer, rc = ssh_buffer_add_data(buffer,
ssh_string_data(kdfoptions), ssh_string_data(kdfoptions),
ssh_string_len(kdfoptions)); (uint32_t)ssh_string_len(kdfoptions));
if (rc != SSH_ERROR){ if (rc != SSH_ERROR){
rc = ssh_buffer_unpack(buffer, "Sd", &salt, &rounds); 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_set_secure(privkey_buffer);
ssh_buffer_add_data(privkey_buffer, ssh_buffer_add_data(privkey_buffer,
ssh_string_data(privkeys), ssh_string_data(privkeys),
ssh_string_len(privkeys)); (uint32_t)ssh_string_len(privkeys));
rc = ssh_buffer_unpack(privkey_buffer, "dd", &checkint1, &checkint2); rc = ssh_buffer_unpack(privkey_buffer, "dd", &checkint1, &checkint2);
if (rc == SSH_ERROR || 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, buf, size, 0, 0,
pgp->data); pgp->data);
if (rc == 0) { 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 BIGNUM *pr = NULL, *ps = NULL;
const unsigned char *raw_sig_data = NULL; const unsigned char *raw_sig_data = NULL;
size_t raw_sig_len; long raw_sig_len;
ECDSA_SIG *ecdsa_sig; 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) { if (raw_sig_data == NULL) {
return 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); ecdsa_sig = d2i_ECDSA_SIG(NULL, &raw_sig_data, raw_sig_len);
if (ecdsa_sig == NULL) { if (ecdsa_sig == NULL) {
@ -1977,7 +1977,7 @@ static int pki_signature_from_rsa_blob(const ssh_key pubkey,
const ssh_string sig_blob, const ssh_string sig_blob,
ssh_signature sig) ssh_signature sig)
{ {
uint32_t pad_len = 0; size_t pad_len = 0;
char *blob_orig = NULL; char *blob_orig = NULL;
char *blob_padded_data = NULL; char *blob_padded_data = NULL;
ssh_string sig_blob_padded = 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, rc = ssh_buffer_add_data(buf,
ssh_string_data(sig_blob), ssh_string_data(sig_blob),
ssh_string_len(sig_blob)); (uint32_t)ssh_string_len(sig_blob));
if (rc < 0) { if (rc < 0) {
goto error; goto error;
} }
@ -2511,7 +2511,7 @@ int pki_verify_data_signature(ssh_signature signature,
EVP_PKEY *pkey = NULL; EVP_PKEY *pkey = NULL;
unsigned char *raw_sig_data = NULL; unsigned char *raw_sig_data = NULL;
unsigned int raw_sig_len; size_t raw_sig_len;
/* Function return code /* Function return code
* Do not change this variable throughout the function until the signature * 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_context_write(session->pcap_ctx,
SSH_PCAP_DIR_IN, SSH_PCAP_DIR_IN,
buffer, buffer,
i + 1, (uint32_t)(i + 1),
i + 1); (uint32_t)(i + 1));
} }
#endif #endif
if (buffer[i] == '\r') { 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]; return sftp->ext->data[idx];
} }
int sftp_extension_supported(sftp_session sftp, const char *name, int
const char *data) { sftp_extension_supported(sftp_session sftp,
size_t i, n; const char *name,
const char *data)
{
unsigned int i, n;
if (sftp == NULL || name == NULL || data == NULL) { 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; 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){ 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. * requested to provide less surprises to the calling applications.
*/ */
if (count > sftp->limits->max_read_length) { 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(); 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; sftp_status_message status;
ssh_string datastring; ssh_string datastring;
int rc, err = SSH_OK; int rc, err = SSH_OK;
uint32_t len; size_t len;
if (file == NULL) { if (file == NULL) {
return SSH_ERROR; 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); file->offset = file->offset - (size - len);
memcpy(data, ssh_string_data(datastring), len); memcpy(data, ssh_string_data(datastring), len);
SSH_STRING_FREE(datastring); SSH_STRING_FREE(datastring);
return len; return (int)len;
default: default:
ssh_set_error(sftp->session,SSH_FATAL,"Received message %d during read!",msg->packet_type); ssh_set_error(sftp->session,SSH_FATAL,"Received message %d during read!",msg->packet_type);
sftp_message_free(msg); 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. * requested to provide less surprises to the calling applications.
*/ */
if (count > sftp->limits->max_write_length) { 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, 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 */ /* Apply a cap on the length a user is allowed to read */
if (len > sftp->limits->max_read_length) { 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) { 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 */ /* Apply a cap on the length a user is allowed to write */
if (len > sftp->limits->max_write_length) { 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) { 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->permissions = z_st->st_mode;
z_attr->flags |= (uint32_t)SSH_FILEXFER_ATTR_ACMODTIME; z_attr->flags |= (uint32_t)SSH_FILEXFER_ATTR_ACMODTIME;
z_attr->atime = z_st->st_atime; z_attr->atime = (uint32_t)z_st->st_atime;
z_attr->mtime = z_st->st_mtime; z_attr->mtime = (uint32_t)z_st->st_mtime;
} }
static void static void

View File

@ -312,7 +312,8 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p,
} }
/* Rollback the unused space */ /* 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 (nread == 0) {
if (p != NULL) { 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), processed = s->callbacks->data(ssh_buffer_get(s->in_buffer),
ssh_buffer_get_len(s->in_buffer), ssh_buffer_get_len(s->in_buffer),
s->callbacks->userdata); 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)); } while ((processed > 0) && (s->state == SSH_SOCKET_CONNECTED));
/* p may have been freed, so don't use it /* 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; 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) { if (s->session->socket_counter != NULL) {
s->session->socket_counter->out_bytes += bwritten; 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; return NULL;
} }
str->size = htonl(size); str->size = htonl((uint32_t)size);
str->data[0] = 0; str->data[0] = 0;
return str; return str;

View File

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