mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-03 20:42:48 -05:00
Revamp of EOF handling in all network connections, pipes and other
data channels. Should comprehensively fix 'half-closed', in principle, though it's a big and complicated change and so there's a good chance I've made at least one mistake somewhere. All connections should now be rigorous about propagating end-of-file (or end-of-data-stream, or socket shutdown, or whatever) independently in both directions, except in frontends with no mechanism for sending explicit EOF (e.g. interactive terminal windows) or backends which are basically always used for interactive sessions so it's unlikely that an application would be depending on independent EOF (telnet, rlogin). EOF should now never accidentally be sent while there's still buffered data to go out before it. (May help fix 'portfwd-corrupt', and also I noticed recently that the ssh main session channel can accidentally have MSG_EOF sent before the output bufchain is clear, leading to embarrassment when it subsequently does send the output). [originally from svn r9279]
This commit is contained in:
17
psftp.c
17
psftp.c
@ -37,6 +37,7 @@ char *pwd, *homedir;
|
||||
static Backend *back;
|
||||
static void *backhandle;
|
||||
static Conf *conf;
|
||||
int sent_eof = FALSE;
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Higher-level helper functions used in commands.
|
||||
@ -980,6 +981,7 @@ int sftp_cmd_close(struct sftp_command *cmd)
|
||||
if (back != NULL && back->connected(backhandle)) {
|
||||
char ch;
|
||||
back->special(backhandle, TS_EOF);
|
||||
sent_eof = TRUE;
|
||||
sftp_recvdata(&ch, 1);
|
||||
}
|
||||
do_sftp_cleanup();
|
||||
@ -2362,6 +2364,7 @@ void do_sftp_cleanup()
|
||||
char ch;
|
||||
if (back) {
|
||||
back->special(backhandle, TS_EOF);
|
||||
sent_eof = TRUE;
|
||||
sftp_recvdata(&ch, 1);
|
||||
back->free(backhandle);
|
||||
sftp_cleanup_request();
|
||||
@ -2570,6 +2573,19 @@ int from_backend_untrusted(void *frontend_handle, const char *data, int len)
|
||||
assert(!"Unexpected call to from_backend_untrusted()");
|
||||
return 0; /* not reached */
|
||||
}
|
||||
int from_backend_eof(void *frontend)
|
||||
{
|
||||
/*
|
||||
* We expect to be the party deciding when to close the
|
||||
* connection, so if we see EOF before we sent it ourselves, we
|
||||
* should panic.
|
||||
*/
|
||||
if (!sent_eof) {
|
||||
connection_fatal(frontend,
|
||||
"Received unexpected end-of-file from SFTP server");
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
int sftp_recvdata(char *buf, int len)
|
||||
{
|
||||
outptr = (unsigned char *) buf;
|
||||
@ -2952,6 +2968,7 @@ int psftp_main(int argc, char *argv[])
|
||||
if (back != NULL && back->connected(backhandle)) {
|
||||
char ch;
|
||||
back->special(backhandle, TS_EOF);
|
||||
sent_eof = TRUE;
|
||||
sftp_recvdata(&ch, 1);
|
||||
}
|
||||
do_sftp_cleanup();
|
||||
|
Reference in New Issue
Block a user