From 313c4f6f3d83ed1f181e195055b14e46d29c8eb8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 2 May 2009 11:13:42 +0200 Subject: [PATCH 1/2] Tiny logic simplification: Remove a pointless else branch --- source/smbd/reply.c | 26 +++++++++++--------------- 1 files changed, 11 insertions(+), 15 deletions(-) diff --git a/source/smbd/reply.c b/source/smbd/reply.c index a374b65..c4c363b 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -3273,25 +3273,21 @@ normal_read: } TALLOC_FREE(req->outbuf); return; - } else { - reply_outbuf(req, 12, smb_maxcnt); - - nread = read_file(fsp, smb_buf(req->outbuf), startpos, - smb_maxcnt); - if (nread < 0) { - reply_unixerror(req, ERRDOS, ERRnoaccess); - return; - } - - setup_readX_header((char *)req->outbuf, nread); - - DEBUG( 3, ( "send_file_readX fnum=%d max=%d nread=%d\n", - fsp->fnum, (int)smb_maxcnt, (int)nread ) ); + } - chain_reply(req); + reply_outbuf(req, 12, smb_maxcnt); + nread = read_file(fsp, smb_buf(req->outbuf), startpos, smb_maxcnt); + if (nread < 0) { + reply_unixerror(req, ERRDOS, ERRnoaccess); return; } + setup_readX_header((char *)req->outbuf, nread); + + DEBUG( 3, ("send_file_readX fnum=%d max=%d nread=%d\n", fsp->fnum, + (int)smb_maxcnt, (int)nread ) ); + + chain_reply(req); } /**************************************************************************** -- 1.6.2.1 From 6213c0bf581935541c7ff9ecc20456c0abb1b42e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 2 May 2009 11:31:37 +0200 Subject: [PATCH 2/2] Fix bug 6302: Give the VFS a chance to read from 0-byte files --- source/smbd/reply.c | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/smbd/reply.c b/source/smbd/reply.c index c4c363b..b1f4132 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -3172,14 +3172,13 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req, return; } - if (startpos > sbuf.st_size) { - smb_maxcnt = 0; - } else if (smb_maxcnt > (sbuf.st_size - startpos)) { - smb_maxcnt = (sbuf.st_size - startpos); - } - - if (smb_maxcnt == 0) { - goto normal_read; + if (!S_ISREG(sbuf.st_mode) || (startpos > sbuf.st_size) + || (smb_maxcnt > (sbuf.st_size - startpos))) { + /* + * We already know that we would do a short read, so don't + * try the sendfile() path. + */ + goto nosendfile_read; } #if defined(WITH_SENDFILE) @@ -3275,6 +3274,8 @@ normal_read: return; } +nosendfile_read: + reply_outbuf(req, 12, smb_maxcnt); nread = read_file(fsp, smb_buf(req->outbuf), startpos, smb_maxcnt); -- 1.6.2.1