X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/ee07dce4bc01900faf5c9b14e14803705e239b5d..c99deca40eecb33ffe93e2290337833afb9493aa:/psftp.c diff --git a/psftp.c b/psftp.c index 5f91822d..482d66ee 100644 --- a/psftp.c +++ b/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. @@ -829,7 +830,17 @@ char *sftp_wildcard_get_filename(SftpWildcardMatcher *swcm) printf("%s: reading directory: %s\n", swcm->prefix, fxp_error()); return NULL; - } + } else if (swcm->names->nnames == 0) { + /* + * Another failure mode which we treat as EOF is if + * the server reports success from FXP_READDIR but + * returns no actual names. This is unusual, since + * from most servers you'd expect at least "." and + * "..", but there's nothing forbidding a server from + * omitting those if it wants to. + */ + return NULL; + } swcm->namepos = 0; } @@ -980,6 +991,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 +2374,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 +2583,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 +2978,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();