mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-02 10:53:16 +03:00
first conversion of a malloc => buffer in the sftp handle struct
This commit is contained in:
@@ -539,6 +539,11 @@ struct _LIBSSH2_SFTP_HANDLE
|
|||||||
LIBSSH2_SFTP *sftp;
|
LIBSSH2_SFTP *sftp;
|
||||||
LIBSSH2_SFTP_HANDLE *prev, *next;
|
LIBSSH2_SFTP_HANDLE *prev, *next;
|
||||||
|
|
||||||
|
/* This is a pre-allocated buffer used for sending SFTP requests as the
|
||||||
|
whole thing might not get sent in one go. This buffer is used for read,
|
||||||
|
write, close and MUST thus be big enough to suit all these. */
|
||||||
|
unsigned char request_packet[SFTP_HANDLE_MAXLEN + 25];
|
||||||
|
|
||||||
char handle[SFTP_HANDLE_MAXLEN];
|
char handle[SFTP_HANDLE_MAXLEN];
|
||||||
int handle_len;
|
int handle_len;
|
||||||
|
|
||||||
|
|||||||
16
src/sftp.c
16
src/sftp.c
@@ -726,10 +726,6 @@ libssh2_sftp_shutdown(LIBSSH2_SFTP * sftp)
|
|||||||
LIBSSH2_FREE(sftp->channel->session, sftp->open_packet);
|
LIBSSH2_FREE(sftp->channel->session, sftp->open_packet);
|
||||||
sftp->open_packet = NULL;
|
sftp->open_packet = NULL;
|
||||||
}
|
}
|
||||||
if (sftp->read_packet) {
|
|
||||||
LIBSSH2_FREE(sftp->channel->session, sftp->read_packet);
|
|
||||||
sftp->read_packet = NULL;
|
|
||||||
}
|
|
||||||
if (sftp->readdir_packet) {
|
if (sftp->readdir_packet) {
|
||||||
LIBSSH2_FREE(sftp->channel->session, sftp->readdir_packet);
|
LIBSSH2_FREE(sftp->channel->session, sftp->readdir_packet);
|
||||||
sftp->readdir_packet = NULL;
|
sftp->readdir_packet = NULL;
|
||||||
@@ -984,12 +980,7 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
|
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
|
||||||
"Reading %lu bytes from SFTP handle",
|
"Reading %lu bytes from SFTP handle",
|
||||||
(unsigned long) buffer_maxlen);
|
(unsigned long) buffer_maxlen);
|
||||||
packet = LIBSSH2_ALLOC(session, packet_len);
|
packet = handle->request_packet;
|
||||||
if (!packet) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
|
||||||
"Unable to allocate memory for FXP_READ packet", 0);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
sftp->read_state = libssh2_NB_state_allocated;
|
sftp->read_state = libssh2_NB_state_allocated;
|
||||||
} else {
|
} else {
|
||||||
packet = sftp->read_packet;
|
packet = sftp->read_packet;
|
||||||
@@ -1065,7 +1056,6 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
non-blocking mode! */
|
non-blocking mode! */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||||
"Unable to send FXP_READ command", 0);
|
"Unable to send FXP_READ command", 0);
|
||||||
LIBSSH2_FREE(session, packet);
|
|
||||||
sftp->read_packet = NULL;
|
sftp->read_packet = NULL;
|
||||||
sftp->read_state = libssh2_NB_state_idle;
|
sftp->read_state = libssh2_NB_state_idle;
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1085,7 +1075,6 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
} else if (retcode) {
|
} else if (retcode) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
|
||||||
"Timeout waiting for status message", 0);
|
"Timeout waiting for status message", 0);
|
||||||
LIBSSH2_FREE(session, packet);
|
|
||||||
sftp->read_packet = NULL;
|
sftp->read_packet = NULL;
|
||||||
sftp->read_state = libssh2_NB_state_idle;
|
sftp->read_state = libssh2_NB_state_idle;
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1097,7 +1086,6 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case SSH_FXP_STATUS:
|
case SSH_FXP_STATUS:
|
||||||
retcode = libssh2_ntohu32(data + 5);
|
retcode = libssh2_ntohu32(data + 5);
|
||||||
LIBSSH2_FREE(session, packet);
|
|
||||||
LIBSSH2_FREE(session, data);
|
LIBSSH2_FREE(session, data);
|
||||||
sftp->read_packet = NULL;
|
sftp->read_packet = NULL;
|
||||||
sftp->read_state = libssh2_NB_state_idle;
|
sftp->read_state = libssh2_NB_state_idle;
|
||||||
@@ -1114,7 +1102,6 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
case SSH_FXP_DATA:
|
case SSH_FXP_DATA:
|
||||||
bytes_read = libssh2_ntohu32(data + 5);
|
bytes_read = libssh2_ntohu32(data + 5);
|
||||||
if (bytes_read > (data_len - 9)) {
|
if (bytes_read > (data_len - 9)) {
|
||||||
LIBSSH2_FREE(session, packet);
|
|
||||||
sftp->read_packet = NULL;
|
sftp->read_packet = NULL;
|
||||||
sftp->read_state = libssh2_NB_state_idle;
|
sftp->read_state = libssh2_NB_state_idle;
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1135,7 +1122,6 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBSSH2_FREE(session, packet);
|
|
||||||
sftp->read_packet = NULL;
|
sftp->read_packet = NULL;
|
||||||
sftp->read_state = libssh2_NB_state_idle;
|
sftp->read_state = libssh2_NB_state_idle;
|
||||||
return total_read;
|
return total_read;
|
||||||
|
|||||||
Reference in New Issue
Block a user