Don't save allocated packet size until it has actually been allocated
The allocated packet size is internal state which needs to match reality in order to avoid problems. This commit fixes #211.
Этот коммит содержится в:
родитель
3ce2628140
Коммит
516fa7fdd9
@ -272,6 +272,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
|
|||||||
unsigned char block[MAX_BLOCKSIZE];
|
unsigned char block[MAX_BLOCKSIZE];
|
||||||
int blocksize;
|
int blocksize;
|
||||||
int encrypted = 1;
|
int encrypted = 1;
|
||||||
|
size_t total_num;
|
||||||
|
|
||||||
/* default clear the bit */
|
/* default clear the bit */
|
||||||
session->socket_block_directions &= ~LIBSSH2_SESSION_BLOCK_INBOUND;
|
session->socket_block_directions &= ~LIBSSH2_SESSION_BLOCK_INBOUND;
|
||||||
@ -431,7 +432,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
|
|||||||
|
|
||||||
/* total_num is the number of bytes following the initial
|
/* total_num is the number of bytes following the initial
|
||||||
(5 bytes) packet length and padding length fields */
|
(5 bytes) packet length and padding length fields */
|
||||||
p->total_num =
|
total_num =
|
||||||
p->packet_length - 1 +
|
p->packet_length - 1 +
|
||||||
(encrypted ? session->remote.mac->mac_len : 0);
|
(encrypted ? session->remote.mac->mac_len : 0);
|
||||||
|
|
||||||
@ -443,16 +444,17 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session)
|
|||||||
* or less (including length, padding length, payload,
|
* or less (including length, padding length, payload,
|
||||||
* padding, and MAC.)."
|
* padding, and MAC.)."
|
||||||
*/
|
*/
|
||||||
if (p->total_num > LIBSSH2_PACKET_MAXPAYLOAD) {
|
if (total_num > LIBSSH2_PACKET_MAXPAYLOAD) {
|
||||||
return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
|
return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a packet handle put data into. We get one to
|
/* Get a packet handle put data into. We get one to
|
||||||
hold all data, including padding and MAC. */
|
hold all data, including padding and MAC. */
|
||||||
p->payload = LIBSSH2_ALLOC(session, p->total_num);
|
p->payload = LIBSSH2_ALLOC(session, total_num);
|
||||||
if (!p->payload) {
|
if (!p->payload) {
|
||||||
return LIBSSH2_ERROR_ALLOC;
|
return LIBSSH2_ERROR_ALLOC;
|
||||||
}
|
}
|
||||||
|
p->total_num = total_num;
|
||||||
/* init write pointer to start of payload buffer */
|
/* init write pointer to start of payload buffer */
|
||||||
p->wptr = p->payload;
|
p->wptr = p->payload;
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user