httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1331110 - in /httpd/httpd/trunk: ./ modules/cache/ modules/dav/fs/ modules/filters/ modules/generators/ modules/loggers/ modules/mappers/ modules/slotmem/ support/
Date Thu, 26 Apr 2012 21:44:52 GMT
Author: sf
Date: Thu Apr 26 21:44:51 2012
New Revision: 1331110

URL: http://svn.apache.org/viewvc?rev=1331110&view=rev
Log:
Replace use of apr_file_write() with apr_file_write_full() to prevent
incomplete writes.

Add comments in some places where error handling/logging is missing.

PR: 53131.
Submitted by: Nicolas Viennot <apache viennot biz>, Stefan Fritsch

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/modules/cache/mod_cache_disk.c
    httpd/httpd/trunk/modules/dav/fs/lock.c
    httpd/httpd/trunk/modules/filters/mod_ext_filter.c
    httpd/httpd/trunk/modules/generators/mod_cgid.c
    httpd/httpd/trunk/modules/loggers/mod_log_config.c
    httpd/httpd/trunk/modules/loggers/mod_log_forensic.c
    httpd/httpd/trunk/modules/mappers/mod_rewrite.c
    httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c
    httpd/httpd/trunk/support/rotatelogs.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Thu Apr 26 21:44:51 2012
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) various modules, rotatelogs: Replace use of apr_file_write() with
+     apr_file_write_full() to prevent incomplete writes. PR 53131.
+     [Nicolas Viennot <apache viennot biz>, Stefan Fritsch]
+
   *) core: Fix segfault in logging if r->useragent_addr or c->client_addr is
      unset. [Stefan Fritsch]
 

Modified: httpd/httpd/trunk/modules/cache/mod_cache_disk.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_cache_disk.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_cache_disk.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_cache_disk.c Thu Apr 26 21:44:51 2012
@@ -739,8 +739,7 @@ static apr_status_t store_array(apr_file
         iov[1].iov_base = CRLF;
         iov[1].iov_len = sizeof(CRLF) - 1;
 
-        rv = apr_file_writev(fd, (const struct iovec *) &iov, 2,
-                             &amt);
+        rv = apr_file_writev_full(fd, (const struct iovec *) &iov, 2, &amt);
         if (rv != APR_SUCCESS) {
             return rv;
         }
@@ -749,8 +748,7 @@ static apr_status_t store_array(apr_file
     iov[0].iov_base = CRLF;
     iov[0].iov_len = sizeof(CRLF) - 1;
 
-    return apr_file_writev(fd, (const struct iovec *) &iov, 1,
-                         &amt);
+    return apr_file_writev_full(fd, (const struct iovec *) &iov, 1, &amt);
 }
 
 static apr_status_t read_table(cache_handle_t *handle, request_rec *r,
@@ -898,8 +896,7 @@ static apr_status_t store_table(apr_file
             iov[3].iov_base = CRLF;
             iov[3].iov_len = sizeof(CRLF) - 1;
 
-            rv = apr_file_writev(fd, (const struct iovec *) &iov, 4,
-                                 &amt);
+            rv = apr_file_writev_full(fd, (const struct iovec *) &iov, 4, &amt);
             if (rv != APR_SUCCESS) {
                 return rv;
             }
@@ -907,8 +904,7 @@ static apr_status_t store_table(apr_file
     }
     iov[0].iov_base = CRLF;
     iov[0].iov_len = sizeof(CRLF) - 1;
-    rv = apr_file_writev(fd, (const struct iovec *) &iov, 1,
-                         &amt);
+    rv = apr_file_writev_full(fd, (const struct iovec *) &iov, 1, &amt);
     return rv;
 }
 
@@ -974,7 +970,7 @@ static apr_status_t write_headers(cache_
             }
 
             amt = sizeof(format);
-            rv = apr_file_write(dobj->vary.tempfd, &format, &amt);
+            rv = apr_file_write_full(dobj->vary.tempfd, &format, amt, NULL);
             if (rv != APR_SUCCESS) {
                 ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, APLOGNO(00722)
                         "could not write to vary file %s",
@@ -985,8 +981,8 @@ static apr_status_t write_headers(cache_
             }
 
             amt = sizeof(h->cache_obj->info.expire);
-            rv = apr_file_write(dobj->vary.tempfd, &h->cache_obj->info.expire,
-                    &amt);
+            rv = apr_file_write_full(dobj->vary.tempfd,
+                                     &h->cache_obj->info.expire, amt, NULL);
             if (rv != APR_SUCCESS) {
                 ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, APLOGNO(00723)
                         "could not write to vary file %s",
@@ -1051,7 +1047,8 @@ static apr_status_t write_headers(cache_
     iov[1].iov_base = (void*)dobj->name;
     iov[1].iov_len = disk_info.name_len;
 
-    rv = apr_file_writev(dobj->hdrs.tempfd, (const struct iovec *) &iov, 2, &amt);
+    rv = apr_file_writev_full(dobj->hdrs.tempfd, (const struct iovec *) &iov,
+                              2, &amt);
     if (rv != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, APLOGNO(00726)
                 "could not write info to header file %s",

Modified: httpd/httpd/trunk/modules/dav/fs/lock.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/dav/fs/lock.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/dav/fs/lock.c (original)
+++ httpd/httpd/trunk/modules/dav/fs/lock.c Thu Apr 26 21:44:51 2012
@@ -845,7 +845,7 @@ static dav_error * dav_fs_save_locknull_
     }
 
     amt = pbuf->cur_len;
-    if ((rv = apr_file_write(file, pbuf->buf, &amt)) != APR_SUCCESS
+    if ((rv = apr_file_write_full(file, pbuf->buf, amt, &amt)) != APR_SUCCESS
         || amt != pbuf->cur_len) {
         err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv,
                             apr_psprintf(p,

Modified: httpd/httpd/trunk/modules/filters/mod_ext_filter.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_ext_filter.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_ext_filter.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_ext_filter.c Thu Apr 26 21:44:51 2012
@@ -681,9 +681,9 @@ static apr_status_t pass_data_to_filter(
 
     do {
         tmplen = len - bytes_written;
-        rv = apr_file_write(ctx->proc->in,
+        rv = apr_file_write_full(ctx->proc->in,
                        (const char *)data + bytes_written,
-                       &tmplen);
+                       tmplen, &tmplen);
         bytes_written += tmplen;
         if (rv != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(rv)) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r, APLOGNO(01461)

Modified: httpd/httpd/trunk/modules/generators/mod_cgid.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/generators/mod_cgid.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/generators/mod_cgid.c (original)
+++ httpd/httpd/trunk/modules/generators/mod_cgid.c Thu Apr 26 21:44:51 2012
@@ -1155,7 +1155,7 @@ static int log_script(request_rec *r, cg
             apr_file_puts("%stdout\n", f);
             first = 0;
         }
-        apr_file_write(f, buf, &len);
+        apr_file_write_full(f, buf, len, NULL);
         apr_file_puts("\n", f);
     }
 

Modified: httpd/httpd/trunk/modules/loggers/mod_log_config.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/loggers/mod_log_config.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/loggers/mod_log_config.c (original)
+++ httpd/httpd/trunk/modules/loggers/mod_log_config.c Thu Apr 26 21:44:51 2012
@@ -1048,7 +1048,8 @@ static const char *process_item(request_
 static void flush_log(buffered_log *buf)
 {
     if (buf->outcnt && buf->handle != NULL) {
-        apr_file_write(buf->handle, buf->outbuf, &buf->outcnt);
+        /* XXX: error handling */
+        apr_file_write_full(buf->handle, buf->outbuf, buf->outcnt, NULL);
         buf->outcnt = 0;
     }
 }
@@ -1539,7 +1540,7 @@ static apr_status_t ap_default_log_write
         s += strl[i];
     }
 
-    rv = apr_file_write((apr_file_t*)handle, str, &len);
+    rv = apr_file_write_full((apr_file_t*)handle, str, len, NULL);
 
     return rv;
 }
@@ -1618,7 +1619,7 @@ static apr_status_t ap_buffered_log_writ
             s += strl[i];
         }
         w = len;
-        rv = apr_file_write(buf->handle, str, &w);
+        rv = apr_file_write_full(buf->handle, str, w, NULL);
 
     }
     else {

Modified: httpd/httpd/trunk/modules/loggers/mod_log_forensic.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/loggers/mod_log_forensic.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/loggers/mod_log_forensic.c (original)
+++ httpd/httpd/trunk/modules/loggers/mod_log_forensic.c Thu Apr 26 21:44:51 2012
@@ -222,7 +222,7 @@ static int log_before(request_rec *r)
     *h.pos++ = '\n';
 
     n = h.count-1;
-    rv = apr_file_write(cfg->fd, h.log, &n);
+    rv = apr_file_write_full(cfg->fd, h.log, n, &n);
     ap_assert(rv == APR_SUCCESS && n == h.count-1);
 
     apr_table_setn(r->notes, "forensic-id", id);
@@ -246,7 +246,7 @@ static int log_after(request_rec *r)
 
     s = apr_pstrcat(r->pool, "-", id, "\n", NULL);
     l = n = strlen(s);
-    rv = apr_file_write(cfg->fd, s, &n);
+    rv = apr_file_write_full(cfg->fd, s, n, &n);
     ap_assert(rv == APR_SUCCESS && n == l);
 
     return OK;

Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrite.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
+++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Thu Apr 26 21:44:51 2012
@@ -1401,9 +1401,10 @@ static char *lookup_map_program(request_
     /* write out the request key */
 #ifdef NO_WRITEV
     nbytes = strlen(key);
-    apr_file_write(fpin, key, &nbytes);
+    /* XXX: error handling */
+    apr_file_write_full(fpin, key, nbytes, NULL);
     nbytes = 1;
-    apr_file_write(fpin, "\n", &nbytes);
+    apr_file_write_full(fpin, "\n", nbytes, NULL);
 #else
     iova[0].iov_base = key;
     iova[0].iov_len = strlen(key);
@@ -1411,7 +1412,8 @@ static char *lookup_map_program(request_
     iova[1].iov_len = 1;
 
     niov = 2;
-    apr_file_writev(fpin, iova, niov, &nbytes);
+    /* XXX: error handling */
+    apr_file_writev_full(fpin, iova, niov, &nbytes);
 #endif
 
     buf = apr_palloc(r->pool, REWRITE_PRG_MAP_BUF + 1);

Modified: httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c (original)
+++ httpd/httpd/trunk/modules/slotmem/mod_slotmem_shm.c Thu Apr 26 21:44:51 2012
@@ -166,7 +166,8 @@ static void store_slotmem(ap_slotmem_ins
         }
         nbytes = (slotmem->desc.size * slotmem->desc.num) +
                  (slotmem->desc.num * sizeof(char)) + AP_UNSIGNEDINT_OFFSET;
-        apr_file_write(fp, slotmem->persist, &nbytes);
+	/* XXX: Error handling */
+        apr_file_write_full(fp, slotmem->persist, &nbytes, NULL);
         apr_file_close(fp);
     }
 }

Modified: httpd/httpd/trunk/support/rotatelogs.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/rotatelogs.c?rev=1331110&r1=1331109&r2=1331110&view=diff
==============================================================================
--- httpd/httpd/trunk/support/rotatelogs.c (original)
+++ httpd/httpd/trunk/support/rotatelogs.c Thu Apr 26 21:44:51 2012
@@ -459,7 +459,7 @@ static void doRotate(rotate_config_t *co
             fprintf(stderr, "Error truncating the file %s\n", status->current.name);
             exit(2);
         }
-        if (apr_file_write(status->current.fd, status->errbuf, &nWrite) != APR_SUCCESS)
{
+        if (apr_file_write_full(status->current.fd, status->errbuf, nWrite, NULL) !=
APR_SUCCESS) {
             fprintf(stderr, "Error writing to the file %s\n", status->current.name);
             exit(2);
         }
@@ -687,18 +687,7 @@ int main (int argc, const char * const a
         }
 
         nWrite = nRead;
-        rv = apr_file_write(status.current.fd, buf, &nWrite);
-        if (rv == APR_SUCCESS && nWrite != nRead) {
-            /* buffer partially written, which for rotatelogs means we encountered
-             * an error such as out of space or quota or some other limit reached;
-             * try to write the rest so we get the real error code
-             */
-            apr_size_t nWritten = nWrite;
-
-            nRead  = nRead - nWritten;
-            nWrite = nRead;
-            rv = apr_file_write(status.current.fd, buf + nWritten, &nWrite);
-        }
+        rv = apr_file_write_full(status.current.fd, buf, nWrite, &nWrite);
         if (nWrite != nRead) {
             char strerrbuf[120];
             apr_off_t cur_offset;
@@ -715,7 +704,7 @@ int main (int argc, const char * const a
                          rv, cur_offset, status.nMessCount, strerrbuf);
             nWrite = strlen(status.errbuf);
             apr_file_trunc(status.current.fd, 0);
-            if (apr_file_write(status.current.fd, status.errbuf, &nWrite) != APR_SUCCESS)
{
+            if (apr_file_write_full(status.current.fd, status.errbuf, nWrite, NULL) != APR_SUCCESS)
{
                 fprintf(stderr, "Error writing to the file %s\n", status.current.name);
                 exit(2);
             }



Mime
View raw message