libssh2_sftp_seek64: flush packetlist and buffered data
When seeking to a new position, flush the packetlist and buffered data to prevent already received or pending data to wrongly get used when sftp-reading from the new offset within the file.
This commit is contained in:
12
src/sftp.c
12
src/sftp.c
@@ -1859,8 +1859,18 @@ libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *hnd,
|
|||||||
LIBSSH2_API void
|
LIBSSH2_API void
|
||||||
libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset)
|
libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset)
|
||||||
{
|
{
|
||||||
if(handle)
|
if(handle) {
|
||||||
handle->u.file.offset = handle->u.file.offset_sent = offset;
|
handle->u.file.offset = handle->u.file.offset_sent = offset;
|
||||||
|
/* discard all pending requests and currently read data */
|
||||||
|
sftp_packetlist_flush(handle);
|
||||||
|
|
||||||
|
/* free the left received buffered data */
|
||||||
|
if (handle->u.file.data_left) {
|
||||||
|
LIBSSH2_FREE(handle->sftp->channel->session, handle->u.file.data);
|
||||||
|
handle->u.file.data_left = handle->u.file.data_len = 0;
|
||||||
|
handle->u.file.data = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* libssh2_sftp_seek
|
/* libssh2_sftp_seek
|
||||||
|
Reference in New Issue
Block a user