[nginx] Core: ngx_regex_compile() error handling fixes.

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


details:   http://hg.nginx.org/nginx/rev/e7f6991eca47
branches:  
changeset: 5824:e7f6991eca47
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Mon Sep 08 21:35:53 2014 +0400
description:
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.

diffstat:

 src/core/ngx_regex.c |  14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diffs (38 lines):

diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c
--- a/src/core/ngx_regex.c
+++ b/src/core/ngx_regex.c
@@ -149,7 +149,7 @@ ngx_regex_compile(ngx_regex_compile_t *r
 
     rc->regex = ngx_pcalloc(rc->pool, sizeof(ngx_regex_t));
     if (rc->regex == NULL) {
-        return NGX_ERROR;
+        goto nomem;
     }
 
     rc->regex->code = re;
@@ -159,7 +159,7 @@ ngx_regex_compile(ngx_regex_compile_t *r
     if (ngx_pcre_studies != NULL) {
         elt = ngx_list_push(ngx_pcre_studies);
         if (elt == NULL) {
-            return NGX_ERROR;
+            goto nomem;
         }
 
         elt->regex = rc->regex;
@@ -204,7 +204,15 @@ failed:
 
     rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n)
                   - rc->err.data;
-    return NGX_OK;
+    return NGX_ERROR;
+
+nomem:
+
+    rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
+                               "regex \"%V\" compilation failed: no memory",
+                               &rc->pattern)
+                  - rc->err.data;
+    return NGX_ERROR;
 }
 
 



More information about the nginx-devel mailing list