You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2012/02/06 22:00:31 UTC
svn commit: r1241176 - in /apr/apr/branches/0.9.x: ./ CHANGES
file_io/unix/seek.c
Author: bojan
Date: Mon Feb 6 21:00:31 2012
New Revision: 1241176
URL: http://svn.apache.org/viewvc?rev=1241176&view=rev
Log:
Backport r1044440 from trunk to 0.9.x.
Fix file_trunc for buffered files. Make sure the write buffer is flushed before truncate call
Modified:
apr/apr/branches/0.9.x/ (props changed)
apr/apr/branches/0.9.x/CHANGES
apr/apr/branches/0.9.x/file_io/unix/seek.c
Propchange: apr/apr/branches/0.9.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 6 21:00:31 2012
@@ -1 +1 @@
-/apr/apr/trunk:1236970,1237078,1237507
+/apr/apr/trunk:1044440,1236970,1237078,1237507
Modified: apr/apr/branches/0.9.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/CHANGES?rev=1241176&r1=1241175&r2=1241176&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/0.9.x/CHANGES [utf-8] Mon Feb 6 21:00:31 2012
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes with APR 0.9.21
+ *) Flush write buffer before truncate call on a file.
+ [Mladen Turk]
+
*) Security: oCERT-2011-003
Randomise hashes by providing a seed.
[Bojan Smojver, Branko Čibej, Ruediger Pluem et al.]
Modified: apr/apr/branches/0.9.x/file_io/unix/seek.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/file_io/unix/seek.c?rev=1241176&r1=1241175&r2=1241176&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/file_io/unix/seek.c (original)
+++ apr/apr/branches/0.9.x/file_io/unix/seek.c Mon Feb 6 21:00:31 2012
@@ -98,6 +98,30 @@ APR_DECLARE(apr_status_t) apr_file_seek(
apr_status_t apr_file_trunc(apr_file_t *fp, apr_off_t offset)
{
+ if (fp->buffered) {
+ int rc = 0;
+ file_lock(fp);
+ if (fp->direction == 1 && fp->bufpos != 0) {
+ apr_off_t len = fp->filePtr + fp->bufpos;
+ if (offset < len) {
+ /* New file end fall below our write buffer limit.
+ * Figure out if and what needs to be flushed.
+ */
+ apr_off_t off = len - offset;
+ if (off >= 0 && off <= fp->bufpos)
+ fp->bufpos = fp->bufpos - (size_t)off;
+ else
+ fp->bufpos = 0;
+ }
+ rc = apr_file_flush_locked(fp);
+ /* Reset buffer positions for write mode */
+ fp->bufpos = fp->direction = fp->dataRead = 0;
+ }
+ if (rc) {
+ return rc;
+ }
+ file_unlock(fp);
+ }
if (ftruncate(fp->filedes, offset) == -1) {
return errno;
}