From 25f7043fb312c68759edecfe6dbbfcf1e3d4ded7 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sat, 27 Jul 2019 11:17:32 +0200 Subject: [PATCH] sftpd transfer: close the file before executing any action ... ... that could potentially move or delete it --- sftpd/transfer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sftpd/transfer.go b/sftpd/transfer.go index 00bd2cb4..235567c5 100644 --- a/sftpd/transfer.go +++ b/sftpd/transfer.go @@ -47,6 +47,7 @@ func (t *Transfer) WriteAt(p []byte, off int64) (n int, err error) { // Close method called when the transfer is completed, we log the transfer info func (t *Transfer) Close() error { + err := t.file.Close() elapsed := time.Since(t.start).Nanoseconds() / 1000000 if t.transferType == transferDownload { logger.TransferLog(sftpdDownloadLogSender, t.path, elapsed, t.bytesSent, t.user.Username, t.connectionID) @@ -61,7 +62,7 @@ func (t *Transfer) Close() error { numFiles++ dataprovider.UpdateUserQuota(dataProvider, t.user.Username, numFiles, t.bytesReceived, false) } - return t.file.Close() + return err } func (t *Transfer) handleThrottle() {