]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Handle failed SSH_FXP_CLOSE requests in sftp_put_file.
authorTim Kosse <tim.kosse@filezilla-project.org>
Wed, 28 Dec 2016 14:34:53 +0000 (15:34 +0100)
committerSimon Tatham <anakin@pobox.com>
Thu, 29 Dec 2016 11:18:03 +0000 (11:18 +0000)
It is possible for SSH_FXP_CLOSE requests to fail. This can happen if the
server buffers writes and an error occurs flushing the data to disk while
processing the SSH_FXP_CLOSE request. If the close fails, sftp_put_file now
returns an error as well.

psftp.c
sftp.c
sftp.h

diff --git a/psftp.c b/psftp.c
index d8c4d071f0c3b4c42be646a8aa3d481d4ee71696..7b8b540df933c337a5e76f11ad6c5d17e5ddb017 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -712,7 +712,13 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
   cleanup:
     req = fxp_close_send(fh);
     pktin = sftp_wait_for_reply(req);
-    fxp_close_recv(pktin, req);
+    ret = fxp_close_recv(pktin, req);
+    if (!ret) {
+       if (!err) {
+           printf("error while closing: %s", fxp_error());
+           err = 1;
+       }
+    }
 
     close_rfile(file);
 
diff --git a/sftp.c b/sftp.c
index 3357876c20f2eaebfe032dd4fd5eaa752cc84992..5685c79ea7a68c2b02945c54cef15721efc72a8a 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -658,11 +658,12 @@ struct sftp_request *fxp_close_send(struct fxp_handle *handle)
     return req;
 }
 
-void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req)
+int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
     sfree(req);
     fxp_got_status(pktin);
     sftp_pkt_free(pktin);
+    return fxp_errtype == SSH_FX_OK;
 }
 
 struct sftp_request *fxp_mkdir_send(const char *path)
diff --git a/sftp.h b/sftp.h
index 309845b0847325ec9e8a0ce6b92a97f0069e428a..d9fa6939293a07d94652cd11c1d246ab270e54f5 100644 (file)
--- a/sftp.h
+++ b/sftp.h
@@ -149,10 +149,10 @@ struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin,
                                    struct sftp_request *req);
 
 /*
- * Close a file/dir.
+ * Close a file/dir. Returns 1 on success, 0 on error.
  */
 struct sftp_request *fxp_close_send(struct fxp_handle *handle);
-void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req);
+int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Make a directory.