From 78e657406b3d5fdf3b0038dd7e3bf1c56b18e942 Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Mon, 21 Nov 2011 17:06:15 +0000 Subject: [PATCH] mod_cache_disk: Make sure we check return codes on all writes and attempts to close, and clean up after ourselves in these cases. PR43589. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1204599 13f79535-47bb-0310-9956-ffa450edef68 --- modules/cache/mod_cache_disk.c | 53 +++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/modules/cache/mod_cache_disk.c b/modules/cache/mod_cache_disk.c index 4e174ba2fb..e750b87450 100644 --- a/modules/cache/mod_cache_disk.c +++ b/modules/cache/mod_cache_disk.c @@ -969,23 +969,47 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r) if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, - "cache_disk: could not create temp file %s", + "cache_disk: could not create vary file %s", dobj->vary.tempfile); return rv; } amt = sizeof(format); - apr_file_write(dobj->vary.tempfd, &format, &amt); + rv = apr_file_write(dobj->vary.tempfd, &format, &amt); + if (rv != APR_SUCCESS) { + ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, + "cache_disk: could not write to vary file %s", + dobj->vary.tempfile); + apr_file_close(dobj->vary.tempfd); + apr_pool_destroy(dobj->vary.pool); + return rv; + } amt = sizeof(h->cache_obj->info.expire); - apr_file_write(dobj->vary.tempfd, &h->cache_obj->info.expire, &amt); + rv = apr_file_write(dobj->vary.tempfd, &h->cache_obj->info.expire, + &amt); + if (rv != APR_SUCCESS) { + ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, + "cache_disk: could not write to vary file %s", + dobj->vary.tempfile); + apr_file_close(dobj->vary.tempfd); + apr_pool_destroy(dobj->vary.pool); + return rv; + } varray = apr_array_make(r->pool, 6, sizeof(char*)); tokens_to_array(r->pool, tmp, varray); store_array(dobj->vary.tempfd, varray); - apr_file_close(dobj->vary.tempfd); + rv = apr_file_close(dobj->vary.tempfd); + if (rv != APR_SUCCESS) { + ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, + "cache_disk: could not close vary file %s", + dobj->vary.tempfile); + apr_pool_destroy(dobj->vary.pool); + return rv; + } tmp = regen_key(r->pool, dobj->headers_in, varray, dobj->name); dobj->prefix = dobj->hdrs.file; @@ -1002,7 +1026,7 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r) if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, - "cache_disk: could not create temp file %s", + "cache_disk: could not create header file %s", dobj->hdrs.tempfile); return rv; } @@ -1034,6 +1058,7 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r) "cache_disk: could not write info to header file %s", dobj->hdrs.tempfile); apr_file_close(dobj->hdrs.tempfd); + apr_pool_destroy(dobj->hdrs.pool); return rv; } @@ -1044,6 +1069,7 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r) "cache_disk: could not write out-headers to header file %s", dobj->hdrs.tempfile); apr_file_close(dobj->hdrs.tempfd); + apr_pool_destroy(dobj->hdrs.pool); return rv; } } @@ -1057,11 +1083,19 @@ static apr_status_t write_headers(cache_handle_t *h, request_rec *r) "cache_disk: could not write in-headers to header file %s", dobj->hdrs.tempfile); apr_file_close(dobj->hdrs.tempfd); + apr_pool_destroy(dobj->hdrs.pool); return rv; } } - apr_file_close(dobj->hdrs.tempfd); /* flush and close */ + rv = apr_file_close(dobj->hdrs.tempfd); /* flush and close */ + if (rv != APR_SUCCESS) { + ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, + "cache_disk: could not close header file %s", + dobj->hdrs.tempfile); + apr_pool_destroy(dobj->hdrs.pool); + return rv; + } return APR_SUCCESS; } @@ -1209,7 +1243,12 @@ static apr_status_t store_body(cache_handle_t *h, request_rec *r, const char *cl_header = apr_table_get(r->headers_out, "Content-Length"); if (dobj->data.tempfd) { - apr_file_close(dobj->data.tempfd); + rv = apr_file_close(dobj->data.tempfd); + if (rv != APR_SUCCESS) { + /* Buffered write failed, abandon attempt to write */ + apr_pool_destroy(dobj->data.pool); + return rv; + } } if (r->connection->aborted || r->no_cache) { -- 2.40.0