1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-09-11 13:30:43 +03:00

packet: Fix ssh_packet_socket_callback() return value

According to the documentation the return value is the number of
processed bytes, so the returned value is never negative. We should not
use ssize_t in public headers as it isn't available on Windows! We only
have it defined in priv.h!

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Andreas Schneider
2022-06-21 15:37:48 +02:00
committed by Jakub Jelen
parent 2ba4b51e0f
commit 7bcc2d83a4
5 changed files with 15 additions and 15 deletions

View File

@@ -56,7 +56,7 @@ typedef void (*ssh_callback_int) (int code, void *user);
* @returns number of bytes processed by the callee. The remaining bytes will
* be sent in the next callback message, when more data is available.
*/
typedef ssize_t (*ssh_callback_data) (const void *data, size_t len, void *user);
typedef size_t (*ssh_callback_data) (const void *data, size_t len, void *user);
typedef void (*ssh_callback_int_int) (int code, int errno_code, void *user);

View File

@@ -67,7 +67,7 @@ int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum);
int ssh_packet_parse_type(ssh_session session);
//int packet_flush(ssh_session session, int enforce_blocking);
ssize_t ssh_packet_socket_callback(const void *data, size_t len, void *user);
size_t ssh_packet_socket_callback(const void *data, size_t len, void *user);
void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s);
void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks);
void ssh_packet_remove_callbacks(ssh_session session, ssh_packet_callbacks callbacks);

View File

@@ -94,7 +94,7 @@ static void socket_callback_connected(int code, int errno_code, void *user)
* @param user is a pointer to session
* @returns Number of bytes processed, or zero if the banner is not complete.
*/
static ssize_t callback_receive_banner(const void *data, size_t len, void *user)
static size_t callback_receive_banner(const void *data, size_t len, void *user)
{
char *buffer = (char *)data;
ssh_session session = (ssh_session) user;
@@ -107,7 +107,7 @@ static ssize_t callback_receive_banner(const void *data, size_t len, void *user)
"Wrong state in callback_receive_banner : %d",
session->session_state);
return SSH_ERROR;
return 0;
}
for (i = 0; i < len; ++i) {
#ifdef WITH_PCAP

View File

@@ -1054,7 +1054,7 @@ static bool ssh_packet_need_rekey(ssh_session session,
* @len length of data received. It might not be enough for a complete packet
* @returns number of bytes read and processed.
*/
ssize_t ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
size_t ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
{
ssh_session session = (ssh_session)user;
uint32_t blocksize = 8;
@@ -1069,7 +1069,7 @@ ssize_t ssh_packet_socket_callback(const void *data, size_t receivedlen, void *u
size_t packet_remaining;
uint32_t packet_len, compsize, payloadsize;
uint8_t padding;
uint32_t processed = 0; /* number of bytes processed from the callback */
size_t processed = 0; /* number of bytes processed from the callback */
enum ssh_packet_filter_result_e filter_result;
struct ssh_crypto_struct *crypto = NULL;
bool etm = false;
@@ -1382,7 +1382,7 @@ ssize_t ssh_packet_socket_callback(const void *data, size_t receivedlen, void *u
error:
session->session_state= SSH_SESSION_STATE_ERROR;
SSH_LOG(SSH_LOG_PACKET,"Packet: processed %u bytes", processed);
SSH_LOG(SSH_LOG_PACKET,"Packet: processed %zu bytes", processed);
return processed;
}

View File

@@ -459,12 +459,12 @@ error:
* @param user is a pointer to session
* @returns Number of bytes processed, or zero if the banner is not complete.
*/
static ssize_t callback_receive_banner(const void *data, size_t len, void *user) {
static size_t callback_receive_banner(const void *data, size_t len, void *user) {
char *buffer = (char *) data;
ssh_session session = (ssh_session) user;
char *str = NULL;
size_t i;
ssize_t ret = 0;
size_t processed = 0;
for (i = 0; i < len; i++) {
#ifdef WITH_PCAP
@@ -485,13 +485,13 @@ static ssize_t callback_receive_banner(const void *data, size_t len, void *user)
str = strdup(buffer);
/* number of bytes read */
ret = i + 1;
processed = i + 1;
session->clientbanner = str;
session->session_state = SSH_SESSION_STATE_BANNER_RECEIVED;
SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
session->ssh_connection_callback(session);
return ret;
return processed;
}
if(i > 127) {
@@ -503,7 +503,7 @@ static ssize_t callback_receive_banner(const void *data, size_t len, void *user)
}
}
return ret;
return processed;
}
/* returns 0 until the key exchange is not finished */