apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: r190573 - in /apr/apr-util/branches/1.0.x: CHANGES buckets/apr_buckets_file.c test/testbuckets.c
Date Tue, 14 Jun 2005 10:40:53 GMT
Author: jorton
Date: Tue Jun 14 03:40:50 2005
New Revision: 190573

URL: http://svn.apache.org/viewcvs?rev=190573&view=rev
Log:
Merge r179564 from trunk:

* buckets/apr_buckets_file.c (file_bucket_read): If an EOF was read,
the file must have been truncated; in this case, do not insert a new
FILE bucket, and do return APR_EOF to the caller.

* test/testbuckets.c (test_truncfile): Add test case.

PR: 34708
Submitted by: trawick, jorton

Modified:
    apr/apr-util/branches/1.0.x/CHANGES
    apr/apr-util/branches/1.0.x/buckets/apr_buckets_file.c
    apr/apr-util/branches/1.0.x/test/testbuckets.c

Modified: apr/apr-util/branches/1.0.x/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr-util/branches/1.0.x/CHANGES?rev=190573&r1=190572&r2=190573&view=diff
==============================================================================
--- apr/apr-util/branches/1.0.x/CHANGES (original)
+++ apr/apr-util/branches/1.0.x/CHANGES Tue Jun 14 03:40:50 2005
@@ -1,5 +1,9 @@
 Changes with APR-util 1.0.2
 
+  *) Fix handling of a premature EOF with the FILE bucket; a new bucket
+     is not inserted for each attempt to read past EOF.  PR 34708.
+     [Jeff Trawick, Joe Orton]
+
   *) Fix build failure with non-threaded APR on AIX.  PR 34655.
      [Ryan Murray <rmurray+apache cyberhqz.com>]
 

Modified: apr/apr-util/branches/1.0.x/buckets/apr_buckets_file.c
URL: http://svn.apache.org/viewcvs/apr/apr-util/branches/1.0.x/buckets/apr_buckets_file.c?rev=190573&r1=190572&r2=190573&view=diff
==============================================================================
--- apr/apr-util/branches/1.0.x/buckets/apr_buckets_file.c (original)
+++ apr/apr-util/branches/1.0.x/buckets/apr_buckets_file.c Tue Jun 14 03:40:50 2005
@@ -132,7 +132,7 @@
     apr_bucket_heap_make(e, buf, *len, apr_bucket_free);
 
     /* If we have more to read from the file, then create another bucket */
-    if (filelength > 0) {
+    if (filelength > 0 && rv != APR_EOF) {
         /* for efficiency, we can just build a new apr_bucket struct
          * to wrap around the existing file bucket */
         b = apr_bucket_alloc(sizeof(*b), e->list);
@@ -149,7 +149,7 @@
     }
 
     *str = buf;
-    return APR_SUCCESS;
+    return rv;
 }
 
 APU_DECLARE(apr_bucket *) apr_bucket_file_make(apr_bucket *b, apr_file_t *fd,

Modified: apr/apr-util/branches/1.0.x/test/testbuckets.c
URL: http://svn.apache.org/viewcvs/apr/apr-util/branches/1.0.x/test/testbuckets.c?rev=190573&r1=190572&r2=190573&view=diff
==============================================================================
--- apr/apr-util/branches/1.0.x/test/testbuckets.c (original)
+++ apr/apr-util/branches/1.0.x/test/testbuckets.c Tue Jun 14 03:40:50 2005
@@ -208,6 +208,42 @@
 }
 
 
+/* Regression test for PR 34708, where a file bucket will keep
+ * duplicating itself on being read() when EOF is reached
+ * prematurely. */
+static void test_truncfile(abts_case *tc, void *data)
+{
+    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
+    apr_bucket_brigade *bb = apr_brigade_create(p, ba);
+    apr_file_t *f = make_test_file(tc, "testfile.txt", "hello");
+    apr_bucket *e;
+    const char *buf;
+    apr_size_t len;
+
+    apr_brigade_insert_file(bb, f, 0, 5, p);
+
+    apr_file_trunc(f, 0);
+
+    e = APR_BRIGADE_FIRST(bb);
+
+    ABTS_ASSERT(tc, "single bucket in brigade",
+                APR_BUCKET_NEXT(e) == APR_BRIGADE_SENTINEL(bb));
+
+    apr_bucket_file_enable_mmap(e, 0);
+
+    ABTS_ASSERT(tc, "read gave APR_EOF",
+                apr_bucket_read(e, &buf, &len, APR_BLOCK_READ) == APR_EOF);
+
+    ABTS_ASSERT(tc, "read length 0", len == 0);
+    
+    ABTS_ASSERT(tc, "still a single bucket in brigade",
+                APR_BUCKET_NEXT(e) == APR_BRIGADE_SENTINEL(bb));
+
+    apr_file_close(f);
+    apr_brigade_destroy(bb);
+    apr_bucket_alloc_destroy(ba);
+}
+
 abts_suite *testbuckets(abts_suite *suite)
 {
     suite = ADD_SUITE(suite);
@@ -218,6 +254,7 @@
     abts_run_test(suite, test_split, NULL);
     abts_run_test(suite, test_bwrite, NULL);
     abts_run_test(suite, test_splitline, NULL);
+    abts_run_test(suite, test_truncfile, NULL);
 
     return suite;
 }



Mime
View raw message