]> git.kaiwu.me - nginx.git/commitdiff
Fixed segfault if regex studies list allocation fails.
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 18 Apr 2023 03:28:46 +0000 (06:28 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 18 Apr 2023 03:28:46 +0000 (06:28 +0300)
The rcf->studies list is unconditionally accessed by ngx_regex_cleanup(),
and this used to cause NULL pointer dereference if allocation
failed.  Fix is to set cleanup handler only when allocation succeeds.

src/core/ngx_regex.c

index bebf3b6a83eb49e529cdba63b05c428aa1b20d42..91381f499428b8686c6aeb3c649b0fc5a9aceb45 100644 (file)
@@ -732,14 +732,14 @@ ngx_regex_create_conf(ngx_cycle_t *cycle)
         return NULL;
     }
 
-    cln->handler = ngx_regex_cleanup;
-    cln->data = rcf;
-
     rcf->studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t));
     if (rcf->studies == NULL) {
         return NULL;
     }
 
+    cln->handler = ngx_regex_cleanup;
+    cln->data = rcf;
+
     ngx_regex_studies = rcf->studies;
 
     return rcf;