mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 06:38:37 -05: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:
parent
dfe88e792a
commit
1074a9be4c
15
ssh1bpp.c
15
ssh1bpp.c
@ -104,13 +104,14 @@ void ssh1_bpp_start_compression(BinaryPacketProtocol *bpp)
|
|||||||
bpp_logevent(("Started zlib (RFC1950) compression"));
|
bpp_logevent(("Started zlib (RFC1950) compression"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BPP_READ(ptr, len) do \
|
#define BPP_READ(ptr, len) do \
|
||||||
{ \
|
{ \
|
||||||
crMaybeWaitUntilV(s->bpp.input_eof || \
|
bool success; \
|
||||||
bufchain_try_fetch_consume( \
|
crMaybeWaitUntilV((success = bufchain_try_fetch_consume( \
|
||||||
s->bpp.in_raw, ptr, len)); \
|
s->bpp.in_raw, ptr, len)) || \
|
||||||
if (s->bpp.input_eof) \
|
s->bpp.input_eof); \
|
||||||
goto eof; \
|
if (!success) \
|
||||||
|
goto eof; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void ssh1_bpp_handle_input(BinaryPacketProtocol *bpp)
|
static void ssh1_bpp_handle_input(BinaryPacketProtocol *bpp)
|
||||||
|
@ -51,13 +51,14 @@ static void ssh2_bare_bpp_free(BinaryPacketProtocol *bpp)
|
|||||||
sfree(s);
|
sfree(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BPP_READ(ptr, len) do \
|
#define BPP_READ(ptr, len) do \
|
||||||
{ \
|
{ \
|
||||||
crMaybeWaitUntilV(s->bpp.input_eof || \
|
bool success; \
|
||||||
bufchain_try_fetch_consume( \
|
crMaybeWaitUntilV((success = bufchain_try_fetch_consume( \
|
||||||
s->bpp.in_raw, ptr, len)); \
|
s->bpp.in_raw, ptr, len)) || \
|
||||||
if (s->bpp.input_eof) \
|
s->bpp.input_eof); \
|
||||||
goto eof; \
|
if (!success) \
|
||||||
|
goto eof; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp)
|
static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp)
|
||||||
|
15
ssh2bpp.c
15
ssh2bpp.c
@ -251,13 +251,14 @@ static void ssh2_bpp_enable_pending_compression(struct ssh2_bpp_state *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BPP_READ(ptr, len) do \
|
#define BPP_READ(ptr, len) do \
|
||||||
{ \
|
{ \
|
||||||
crMaybeWaitUntilV(s->bpp.input_eof || \
|
bool success; \
|
||||||
bufchain_try_fetch_consume( \
|
crMaybeWaitUntilV((success = bufchain_try_fetch_consume( \
|
||||||
s->bpp.in_raw, ptr, len)); \
|
s->bpp.in_raw, ptr, len)) || \
|
||||||
if (s->bpp.input_eof) \
|
s->bpp.input_eof); \
|
||||||
goto eof; \
|
if (!success) \
|
||||||
|
goto eof; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define userauth_range(pkttype) ((unsigned)((pkttype) - 50) < 20)
|
#define userauth_range(pkttype) ((unsigned)((pkttype) - 50) < 20)
|
||||||
|
@ -205,12 +205,13 @@ static void ssh_verstring_send(struct ssh_verstring_state *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define BPP_WAITFOR(minlen) do \
|
#define BPP_WAITFOR(minlen) do \
|
||||||
{ \
|
{ \
|
||||||
crMaybeWaitUntilV( \
|
bool success; \
|
||||||
s->bpp.input_eof || \
|
crMaybeWaitUntilV( \
|
||||||
bufchain_size(s->bpp.in_raw) >= (minlen)); \
|
(success = (bufchain_size(s->bpp.in_raw) >= (minlen))) || \
|
||||||
if (s->bpp.input_eof) \
|
s->bpp.input_eof); \
|
||||||
goto eof; \
|
if (!success) \
|
||||||
|
goto eof; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
||||||
@ -284,7 +285,7 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
|||||||
void *data;
|
void *data;
|
||||||
char *nl;
|
char *nl;
|
||||||
|
|
||||||
crMaybeWaitUntilV(bufchain_size(s->bpp.in_raw) > 0);
|
BPP_WAITFOR(1);
|
||||||
bufchain_prefix(s->bpp.in_raw, &data, &len);
|
bufchain_prefix(s->bpp.in_raw, &data, &len);
|
||||||
if ((nl = memchr(data, '\012', len)) != NULL) {
|
if ((nl = memchr(data, '\012', len)) != NULL) {
|
||||||
len = nl - (char *)data + 1;
|
len = nl - (char *)data + 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user