[PATCH 1 of 2] clear err when ngx_regex_compile has allocation failure

Maxim Dounin mdounin at mdounin.ru
Mon Sep 8 20:32:20 UTC 2014


Hello!

On Fri, Sep 05, 2014 at 10:25:18PM +0400, Maxim Dounin wrote:

> Hello!
> 
> On Sun, Aug 17, 2014 at 11:00:29PM +0300, Markus Linnala wrote:
> 
> > # HG changeset patch
> > # User Markus Linnala <Markus.Linnala at cybercom.com>
> > # Date 1408303316 -10800
> > #      Sun Aug 17 22:21:56 2014 +0300
> > # Node ID d350d288cffef0e6395ae1f412842c3b55bc8d42
> > # Parent  0719145489f842b14765506f8856798c2203e3cc
> > clear err when ngx_regex_compile has allocation failure
> > 
> > diff -r 0719145489f8 -r d350d288cffe src/core/ngx_regex.c
> > --- a/src/core/ngx_regex.c	Sun Aug 17 21:59:38 2014 +0300
> > +++ b/src/core/ngx_regex.c	Sun Aug 17 22:21:56 2014 +0300
> > @@ -149,6 +149,7 @@
> >  
> >      rc->regex = ngx_pcalloc(rc->pool, sizeof(ngx_regex_t));
> >      if (rc->regex == NULL) {
> > +        rc->err.len = 0;
> >          return NGX_ERROR;
> >      }
> >  
> > @@ -159,6 +160,7 @@
> >      if (ngx_pcre_studies != NULL) {
> >          elt = ngx_list_push(ngx_pcre_studies);
> >          if (elt == NULL) {
> > +            rc->err.len = 0;
> >              return NGX_ERROR;
> >          }
> 
> This doesn't looks good, as it will result in empty errors being 
> logged in such cases.
> 
> Something like this should be more user-friendly (and it also 
> fixes another long-standing bug):
> 
> # HG changeset patch
> # User Maxim Dounin <mdounin at mdounin.ru>
> # Date 1409938779 -14400
> #      Fri Sep 05 21:39:39 2014 +0400
> # Node ID f43551f64d028de939332ab9b66c3620b4259e08
> # Parent  063f7e75f9efd56f3aaa3d9c24c98ed3f42348ea
> Core: ngx_regex_compile() error handling fixes.
> 
> Now we actually return NGX_ERROR on errors, and provide an error
> string for memory allocation errors.
> 
> Reported by Markus Linnala.

Committed this and other patches with minor changes, thanks.

[...]

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list