Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Mar 2017 16:01:19 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r315910 - head/sys/kern
Message-ID:  <201703241601.v2OG1JdU075253@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Fri Mar 24 16:01:19 2017
New Revision: 315910
URL: https://svnweb.freebsd.org/changeset/base/315910

Log:
  Make sendfile(2) more robust against file change.  This fixes a possible
  crash when the file shrinks.  This also fixes sendfile(2) not sending more
  data in a case when the file grows, and the request is open-ended or
  specifies a size that is greater than old file size.
  
  PR:		217789
  Reviewed by:	gallatin
  MFC after:	10 days

Modified:
  head/sys/kern/kern_sendfile.c

Modified: head/sys/kern/kern_sendfile.c
==============================================================================
--- head/sys/kern/kern_sendfile.c	Fri Mar 24 14:45:58 2017	(r315909)
+++ head/sys/kern/kern_sendfile.c	Fri Mar 24 16:01:19 2017	(r315910)
@@ -689,11 +689,10 @@ retry_space:
 				goto done;
 			}
 			if (va.va_size != obj_size) {
-				if (nbytes == 0)
-					rem += va.va_size - obj_size;
-				else if (offset + nbytes > va.va_size)
-					rem -= (offset + nbytes - va.va_size);
 				obj_size = va.va_size;
+				rem = nbytes ?
+				    omin(nbytes + offset, obj_size) : obj_size;
+				rem -= off;
 			}
 		}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703241601.v2OG1JdU075253>