Fix bug 6302: Give the VFS a chance to read from 0-byte files
authorVolker Lendecke <vl@samba.org>
Sat, 2 May 2009 09:31:37 +0000 (11:31 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 5 May 2009 20:44:47 +0000 (13:44 -0700)
source3/smbd/reply.c

index d2e1f8be5fae949f6edf7768115e6aac70892edc..418c8ba7884928faacddb85a1aa1c323ec9ad3a2 100644 (file)
@@ -3358,14 +3358,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)
@@ -3482,6 +3481,8 @@ normal_read:
                return;
        }
 
+nosendfile_read:
+
        reply_outbuf(req, 12, smb_maxcnt);
 
        nread = read_file(fsp, smb_buf(req->outbuf), startpos, smb_maxcnt);