From 1ed710c2ffc91d8b33b87e572a6075e0126b5826 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 8 Apr 2013 10:32:10 -0700 Subject: [PATCH] Ensure the RECVFILE path in vfs_write_data() operates on a blocking socket. Signed-off-by: Jeremy Allison Reviewed-by: Stefan (metze) Metzmacher --- source3/smbd/vfs.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 856e090ed34..dd74d798800 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -428,14 +428,25 @@ ssize_t vfs_write_data(struct smb_request *req, ssize_t ret; if (req && req->unread_bytes) { + int sockfd = req->sconn->sock; + int old_flags; SMB_ASSERT(req->unread_bytes == N); /* VFS_RECVFILE must drain the socket * before returning. */ req->unread_bytes = 0; - return SMB_VFS_RECVFILE(req->sconn->sock, + /* Ensure the socket is blocking. */ + old_flags = fcntl(sockfd, F_GETFL, 0); + if (set_blocking(sockfd, true) == -1) { + return (ssize_t)-1; + } + ret = SMB_VFS_RECVFILE(sockfd, fsp, (off_t)-1, N); + if (fcntl(sockfd, F_SETFL, old_flags) == -1) { + return (ssize_t)-1; + } + return ret; } while (total < N) { -- 2.11.4.GIT