Return-Path: X-Original-To: apmail-httpd-cvs-archive@www.apache.org Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1AF3F9C63 for ; Fri, 2 Dec 2011 22:18:33 +0000 (UTC) Received: (qmail 30004 invoked by uid 500); 2 Dec 2011 22:18:32 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 29931 invoked by uid 500); 2 Dec 2011 22:18:32 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 29924 invoked by uid 99); 2 Dec 2011 22:18:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 22:18:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 22:18:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 549292388993; Fri, 2 Dec 2011 22:18:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1209736 - in /httpd/httpd/branches/2.4.x: ./ modules/filters/mod_xml2enc.c Date: Fri, 02 Dec 2011 22:18:10 -0000 To: cvs@httpd.apache.org From: sf@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111202221810.549292388993@eris.apache.org> Author: sf Date: Fri Dec 2 22:18:09 2011 New Revision: 1209736 URL: http://svn.apache.org/viewvc?rev=1209736&view=rev Log: Merge r1206850: - Add some error handling for writing to the output filter chain. - Add some ap_assert()s for error cases that probably should not happen (and the following code would break). These fix some compiler warnings about "variable 'rv' set but not used". - Prevent a leak of a bucket in one error case. Modified: httpd/httpd/branches/2.4.x/ (props changed) httpd/httpd/branches/2.4.x/modules/filters/mod_xml2enc.c Propchange: httpd/httpd/branches/2.4.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Fri Dec 2 22:18:09 2011 @@ -1,3 +1,3 @@ /httpd/httpd/branches/revert-ap-ldap:1150158-1150173 /httpd/httpd/branches/wombat-integration:723609-723841 -/httpd/httpd/trunk:1201042,1201111,1201194,1201198,1201202,1202456,1202886,1203859,1204630,1204968,1204990,1205061,1205075,1205379,1205885,1206291,1206587,1207719,1208753,1208835,1209053,1209085,1209417,1209432,1209461,1209601,1209603,1209618,1209623 +/httpd/httpd/trunk:1201042,1201111,1201194,1201198,1201202,1202456,1202886,1203859,1204630,1204968,1204990,1205061,1205075,1205379,1205885,1206291,1206587,1206850,1207719,1208753,1208835,1209053,1209085,1209417,1209432,1209461,1209601,1209603,1209618,1209623 Modified: httpd/httpd/branches/2.4.x/modules/filters/mod_xml2enc.c URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/filters/mod_xml2enc.c?rev=1209736&r1=1209735&r2=1209736&view=diff ============================================================================== --- httpd/httpd/branches/2.4.x/modules/filters/mod_xml2enc.c (original) +++ httpd/httpd/branches/2.4.x/modules/filters/mod_xml2enc.c Fri Dec 2 22:18:09 2011 @@ -50,6 +50,11 @@ module AP_MODULE_DECLARE_DATA xml2enc_mo #define HAVE_ENCODING(enc) \ (((enc)!=XML_CHAR_ENCODING_NONE)&&((enc)!=XML_CHAR_ENCODING_ERROR)) +/* + * XXX: Check all those ap_assert()s ans replace those that should not happen + * XXX: with AP_DEBUG_ASSERT and those that may happen with proper error + * XXX: handling. + */ typedef struct { xmlCharEncoding xml2enc; char* buf; @@ -135,6 +140,7 @@ static void fix_skipto(request_rec* r, x apr_bucket* bstart; rv = apr_brigade_partition(ctx->bbsave, (p-ctx->buf), &bstart); + ap_assert(rv == APR_SUCCESS); while (b = APR_BRIGADE_FIRST(ctx->bbsave), b != bstart) { APR_BUCKET_REMOVE(b); apr_bucket_destroy(b); @@ -199,7 +205,9 @@ static void sniff_encoding(request_rec* if (ap_regexec(seek_meta_ctype, ctx->buf, 1, match, 0) == 0 ) { /* get markers on the start and end of the match */ rv = apr_brigade_partition(ctx->bbsave, match[0].rm_eo, &cute); + ap_assert(rv == APR_SUCCESS); rv = apr_brigade_partition(ctx->bbsave, match[0].rm_so, &cutb); + ap_assert(rv == APR_SUCCESS); /* now set length of useful buf for start-of-data hooks */ ctx->bytes = match[0].rm_so; if (ctx->encoding == NULL) { @@ -329,7 +337,7 @@ static apr_status_t xml2enc_ffunc(ap_fil /* Turn all this off when post-processing */ /* if we don't have enough data to sniff but more's to come, wait */ - rv = apr_brigade_length(ctx->bbsave, 0, &ctx->bblen); + apr_brigade_length(ctx->bbsave, 0, &ctx->bblen); if ((ctx->bblen < BUF_MIN) && (ctx->bblen != -1)) { APR_BRIGADE_DO(b, ctx->bbsave) { if (APR_BUCKET_IS_EOS(b)) { @@ -340,7 +348,8 @@ static apr_status_t xml2enc_ffunc(ap_fil if (!(ctx->flags & ENC_SEEN_EOS)) { /* not enough data to sniff. Wait for more */ APR_BRIGADE_DO(b, ctx->bbsave) { - apr_bucket_setaside(b, f->r->pool); + rv = apr_bucket_setaside(b, f->r->pool); + ap_assert(rv == APR_SUCCESS); } return APR_SUCCESS; } @@ -353,6 +362,7 @@ static apr_status_t xml2enc_ffunc(ap_fil ctx->buf = apr_palloc(f->r->pool, (apr_size_t)(ctx->bblen+1)); ctx->bytes = (apr_size_t)ctx->bblen; rv = apr_brigade_flatten(ctx->bbsave, ctx->buf, &ctx->bytes); + ap_assert(rv == APR_SUCCESS); ctx->buf[ctx->bytes] = 0; sniff_encoding(f->r, ctx); @@ -400,6 +410,7 @@ static apr_status_t xml2enc_ffunc(ap_fil buf = fixbuf; bytes = BUFLEN; rv = apr_brigade_flatten(bb, buf, &bytes); + ap_assert(rv == APR_SUCCESS); if (bytes == insz) { /* this is only what we've already tried to convert. * The brigade is exhausted. @@ -412,7 +423,8 @@ static apr_status_t xml2enc_ffunc(ap_fil rv = ap_fflush(f->next, ctx->bbnext); APR_BRIGADE_CONCAT(ctx->bbsave, bb); APR_BRIGADE_DO(b, ctx->bbsave) { - apr_bucket_setaside(b, f->r->pool); + ap_assert(apr_bucket_setaside(b, f->r->pool) + == APR_SUCCESS); } return rv; } @@ -441,6 +453,7 @@ static apr_status_t xml2enc_ffunc(ap_fil xml2enc_run_preprocess(f, &buf, &bytes); consumed = insz = bytes; while (insz > 0) { + apr_status_t rv2; if (ctx->bytes == ctx->bblen) { /* nothing was converted last time! * break out of this loop! @@ -461,8 +474,13 @@ static apr_status_t xml2enc_ffunc(ap_fil "/%" APR_OFF_T_FMT " bytes", consumed - insz, ctx->bblen - ctx->bytes); consumed = insz; - ap_fwrite(f->next, ctx->bbnext, ctx->buf, - (apr_size_t)ctx->bblen - ctx->bytes); + rv2 = ap_fwrite(f->next, ctx->bbnext, ctx->buf, + (apr_size_t)ctx->bblen - ctx->bytes); + if (rv2 != APR_SUCCESS) { + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv2, f->r, + "ap_fwrite failed"); + return rv2; + } switch (rv) { case APR_SUCCESS: continue; @@ -485,17 +503,22 @@ static apr_status_t xml2enc_ffunc(ap_fil ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r, "Failed to convert input; trying it raw") ; ctx->convset = NULL; - ap_fflush(f->next, ctx->bbnext); - return ap_pass_brigade(f->next, ctx->bbnext); + rv = ap_fflush(f->next, ctx->bbnext); + if (rv != APR_SUCCESS) + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, f->r, + "ap_fflush failed"); + else + rv = ap_pass_brigade(f->next, ctx->bbnext); } } } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r, "xml2enc: error reading data") ; } - if (bdestroy) { + if (bdestroy) apr_bucket_destroy(bdestroy); - } + if (rv != APR_SUCCESS) + return rv; } } return APR_SUCCESS;