Eberhard Mattes' fix for libssh2_packet_read() for when reading very small
chunks at a time.
This commit is contained in:
parent
62f77b1e4b
commit
355c9c634b
@ -252,6 +252,7 @@ libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
|||||||
int numdecrypt;
|
int numdecrypt;
|
||||||
unsigned char block[MAX_BLOCKSIZE];
|
unsigned char block[MAX_BLOCKSIZE];
|
||||||
int blocksize;
|
int blocksize;
|
||||||
|
int minimum;
|
||||||
int encrypted = 1;
|
int encrypted = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -269,6 +270,7 @@ libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
|||||||
here to make the checks below work
|
here to make the checks below work
|
||||||
fine still */
|
fine still */
|
||||||
}
|
}
|
||||||
|
minimum = p->total_num ? p->total_num - p->data_num : blocksize;
|
||||||
|
|
||||||
/* read/use a whole big chunk into a temporary area stored in
|
/* read/use a whole big chunk into a temporary area stored in
|
||||||
the LIBSSH2_SESSION struct. We will decrypt data from that
|
the LIBSSH2_SESSION struct. We will decrypt data from that
|
||||||
@ -283,9 +285,9 @@ libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
|||||||
/* if remainbuf turns negative we have a bad internal error */
|
/* if remainbuf turns negative we have a bad internal error */
|
||||||
assert(remainbuf >= 0);
|
assert(remainbuf >= 0);
|
||||||
|
|
||||||
if(remainbuf < blocksize) {
|
while(remainbuf < minimum) {
|
||||||
/* If we have less than a blocksize left, it is too
|
/* While there is too little data to deal with, read
|
||||||
little data to deal with, read more */
|
more */
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
|
|
||||||
/* move any remainder to the start of the buffer so
|
/* move any remainder to the start of the buffer so
|
||||||
@ -327,11 +329,6 @@ libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
|||||||
/* how much data to deal with from the buffer */
|
/* how much data to deal with from the buffer */
|
||||||
numbytes = remainbuf;
|
numbytes = remainbuf;
|
||||||
|
|
||||||
if(numbytes < blocksize) {
|
|
||||||
/* we can't act on anything less than blocksize */
|
|
||||||
return PACKET_EAGAIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!p->total_num) {
|
if(!p->total_num) {
|
||||||
/* No payload package area allocated yet. To know the
|
/* No payload package area allocated yet. To know the
|
||||||
size of this payload, we need to decrypt the first
|
size of this payload, we need to decrypt the first
|
||||||
@ -401,7 +398,7 @@ libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session)
|
|||||||
|
|
||||||
/* init the data_num field to the number of bytes of
|
/* init the data_num field to the number of bytes of
|
||||||
the package read so far */
|
the package read so far */
|
||||||
p->data_num = blocksize-5;
|
p->data_num = p->wptr - p->payload;
|
||||||
|
|
||||||
/* we already dealt with a blocksize worth of data */
|
/* we already dealt with a blocksize worth of data */
|
||||||
numbytes -= blocksize;
|
numbytes -= blocksize;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user