sftp.c: stop reading when buffer is full
Since we can only store data from a single chunk in filep, we have to stop receiving data as soon as the buffer is full. This adresses the following bug report: https://github.com/libssh2/libssh2/issues/50
This commit is contained in:

committed by
Daniel Stenberg

parent
60874670ef
commit
0d60964632
18
src/sftp.c
18
src/sftp.c
@@ -1531,6 +1531,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
the buffer at the correct index */
|
the buffer at the correct index */
|
||||||
memcpy(sliding_bufferp, data + 9, rc32);
|
memcpy(sliding_bufferp, data + 9, rc32);
|
||||||
filep->offset += rc32;
|
filep->offset += rc32;
|
||||||
|
bytes_in_buffer += rc32;
|
||||||
|
sliding_bufferp += rc32;
|
||||||
|
|
||||||
if(filep->data_len == 0)
|
if(filep->data_len == 0)
|
||||||
/* free the allocated data if not stored to keep */
|
/* free the allocated data if not stored to keep */
|
||||||
@@ -1542,18 +1544,14 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
|
|||||||
next = _libssh2_list_next(&chunk->node);
|
next = _libssh2_list_next(&chunk->node);
|
||||||
_libssh2_list_remove(&chunk->node);
|
_libssh2_list_remove(&chunk->node);
|
||||||
LIBSSH2_FREE(session, chunk);
|
LIBSSH2_FREE(session, chunk);
|
||||||
chunk = NULL;
|
|
||||||
|
/* check if we have space left in the buffer
|
||||||
if(rc32 > 0) {
|
* and either continue to the next chunk or stop
|
||||||
/* continue to the next chunk */
|
*/
|
||||||
bytes_in_buffer += rc32;
|
if (bytes_in_buffer < buffer_size) {
|
||||||
sliding_bufferp += rc32;
|
|
||||||
chunk = next;
|
chunk = next;
|
||||||
} else {
|
} else {
|
||||||
/* A zero-byte read is not necessarily EOF so we must not
|
chunk = NULL;
|
||||||
* return 0 (that would signal EOF to the caller) so
|
|
||||||
* instead we carry on to the next chunk */
|
|
||||||
chunk = next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user