1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

Stop BPPs from handling EOF before reading all data.

The BPP_READ macros in all four BPP implementations (including
sshverstring) had the same bug: if EOF had been seen on the network
input but there was _also_ enough data in the input queue to satisfy
the current request, they would jump straight to complaining about the
EOF rather than processing the available data first.

I spotted this while trying to pipe in test data from a disk file, but
it could easily also lead to us failing to handle the final message in
the connection, e.g. losing the error message sent by the remote in a
DISCONNECT message.
This commit is contained in:
Simon Tatham 2018-11-28 20:16:41 +00:00
parent dfe88e792a
commit 1074a9be4c
4 changed files with 32 additions and 28 deletions

View File

@ -106,10 +106,11 @@ void ssh1_bpp_start_compression(BinaryPacketProtocol *bpp)
#define BPP_READ(ptr, len) do \
{ \
crMaybeWaitUntilV(s->bpp.input_eof || \
bufchain_try_fetch_consume( \
s->bpp.in_raw, ptr, len)); \
if (s->bpp.input_eof) \
bool success; \
crMaybeWaitUntilV((success = bufchain_try_fetch_consume( \
s->bpp.in_raw, ptr, len)) || \
s->bpp.input_eof); \
if (!success) \
goto eof; \
} while (0)

View File

@ -53,10 +53,11 @@ static void ssh2_bare_bpp_free(BinaryPacketProtocol *bpp)
#define BPP_READ(ptr, len) do \
{ \
crMaybeWaitUntilV(s->bpp.input_eof || \
bufchain_try_fetch_consume( \
s->bpp.in_raw, ptr, len)); \
if (s->bpp.input_eof) \
bool success; \
crMaybeWaitUntilV((success = bufchain_try_fetch_consume( \
s->bpp.in_raw, ptr, len)) || \
s->bpp.input_eof); \
if (!success) \
goto eof; \
} while (0)

View File

@ -253,10 +253,11 @@ static void ssh2_bpp_enable_pending_compression(struct ssh2_bpp_state *s)
#define BPP_READ(ptr, len) do \
{ \
crMaybeWaitUntilV(s->bpp.input_eof || \
bufchain_try_fetch_consume( \
s->bpp.in_raw, ptr, len)); \
if (s->bpp.input_eof) \
bool success; \
crMaybeWaitUntilV((success = bufchain_try_fetch_consume( \
s->bpp.in_raw, ptr, len)) || \
s->bpp.input_eof); \
if (!success) \
goto eof; \
} while (0)

View File

@ -206,10 +206,11 @@ static void ssh_verstring_send(struct ssh_verstring_state *s)
#define BPP_WAITFOR(minlen) do \
{ \
bool success; \
crMaybeWaitUntilV( \
s->bpp.input_eof || \
bufchain_size(s->bpp.in_raw) >= (minlen)); \
if (s->bpp.input_eof) \
(success = (bufchain_size(s->bpp.in_raw) >= (minlen))) || \
s->bpp.input_eof); \
if (!success) \
goto eof; \
} while (0)
@ -284,7 +285,7 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
void *data;
char *nl;
crMaybeWaitUntilV(bufchain_size(s->bpp.in_raw) > 0);
BPP_WAITFOR(1);
bufchain_prefix(s->bpp.in_raw, &data, &len);
if ((nl = memchr(data, '\012', len)) != NULL) {
len = nl - (char *)data + 1;