[PATCH 2 of 4] Set done flag on module context to stop further chunk parsing

Maxim Dounin mdounin at mdounin.ru
Wed Mar 28 02:02:23 UTC 2012


Hello!

On Wed, Mar 21, 2012 at 09:28:32PM +0000, Laurence Rowe wrote:

> # HG changeset patch
> # User Laurence Rowe <laurence at lrowe.co.uk>
> # Date 1332363776 0
> # Node ID 151124d060d3f725c02b656d39c10575ff009cdb
> # Parent  28a1437a8b4492530a24d51b85aca7923627c330
> Set done flag on module context to stop further chunk parsing.
> 
> As HTML parsing will recover from non-fatal errors, the return value of
> (x|ht)mlParseChunk cannot be used.
> 
> diff --git a/src/http/modules/ngx_http_xslt_filter_module.c b/src/http/modules/ngx_http_xslt_filter_module.c
> --- a/src/http/modules/ngx_http_xslt_filter_module.c
> +++ b/src/http/modules/ngx_http_xslt_filter_module.c
> @@ -378,7 +378,7 @@
>      err = xmlParseChunk(ctx->ctxt, (char *) b->pos, (int) (b->last - b->pos),
>                          (b->last_buf) || (b->last_in_chain));
>  
> -    if (err == 0) {
> +    if (ctx->done == 0) {
>          b->pos = b->last;
>          return NGX_OK;
>      }
> @@ -463,6 +463,8 @@
>  
>      ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
>                    "libxml2 error: \"%*s\"", n + 1, buf);
> +
> +    ctx->done = 1; /* stop further chunk parsing */
>  }

I believe this doesn't cover all possible fatal errors as returned 
by xmlParseChunk().  At least this one isn't covered:

...
    if (ctxt == NULL)
        return(XML_ERR_INTERNAL_ERROR);
...

While it probably not very common, I still think we need a better 
way to differentiate recoverable errors in html parsing.

Maxim Dounin



More information about the nginx-devel mailing list