Mercurial > hg > nginx
annotate src/core/ngx_regex.c @ 7978:2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
If a configuration parsing fails for some reason, ngx_regex_module_init()
is not called, and ngx_pcre_studies remained set despite the fact that
the pool it was allocated from is already freed. This might result in
a segmentation fault during runtime regular expression compilation, such
as in SSI, for example, in the single process mode, or if a worker process
died and was respawned from a master process in such an inconsistent state.
Fix is to clear ngx_pcre_studies from the pool cleanup handler (which is
anyway used to free JIT-compiled patterns).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 25 Dec 2021 01:07:10 +0300 |
parents | f684178faec9 |
children | 060bf88d2473 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
6 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
12 typedef struct { |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
13 ngx_flag_t pcre_jit; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
14 ngx_list_t *studies; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
15 } ngx_regex_conf_t; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
16 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
17 |
503 | 18 static void * ngx_libc_cdecl ngx_regex_malloc(size_t size); |
19 static void ngx_libc_cdecl ngx_regex_free(void *p); | |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
20 static void ngx_regex_cleanup(void *data); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
22 static ngx_int_t ngx_regex_module_init(ngx_cycle_t *cycle); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
23 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
24 static void *ngx_regex_create_conf(ngx_cycle_t *cycle); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
25 static char *ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
26 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
27 static char *ngx_regex_pcre_jit(ngx_conf_t *cf, void *post, void *data); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
28 static ngx_conf_post_t ngx_regex_pcre_jit_post = { ngx_regex_pcre_jit }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
29 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
30 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
31 static ngx_command_t ngx_regex_commands[] = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
32 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
33 { ngx_string("pcre_jit"), |
6511
640288d0e1bc
Fixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse (as in e444e8f6538b).
Ruslan Ermilov <ru@nginx.com>
parents:
6109
diff
changeset
|
34 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG, |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
35 ngx_conf_set_flag_slot, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
36 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
37 offsetof(ngx_regex_conf_t, pcre_jit), |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
38 &ngx_regex_pcre_jit_post }, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
39 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
40 ngx_null_command |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
41 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
42 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
43 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
44 static ngx_core_module_t ngx_regex_module_ctx = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
45 ngx_string("regex"), |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
46 ngx_regex_create_conf, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
47 ngx_regex_init_conf |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
48 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
49 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
50 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
51 ngx_module_t ngx_regex_module = { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
52 NGX_MODULE_V1, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
53 &ngx_regex_module_ctx, /* module context */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
54 ngx_regex_commands, /* module directives */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
55 NGX_CORE_MODULE, /* module type */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
56 NULL, /* init master */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
57 ngx_regex_module_init, /* init module */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
58 NULL, /* init process */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
59 NULL, /* init thread */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
60 NULL, /* exit thread */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
61 NULL, /* exit process */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
62 NULL, /* exit master */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
63 NGX_MODULE_V1_PADDING |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
64 }; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
65 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 static ngx_pool_t *ngx_pcre_pool; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
68 static ngx_list_t *ngx_pcre_studies; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
70 |
503 | 71 void |
72 ngx_regex_init(void) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 pcre_malloc = ngx_regex_malloc; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 pcre_free = ngx_regex_free; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 |
3325 | 79 static ngx_inline void |
80 ngx_regex_malloc_init(ngx_pool_t *pool) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 ngx_pcre_pool = pool; |
3325 | 83 } |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
84 |
3325 | 85 |
86 static ngx_inline void | |
87 ngx_regex_malloc_done(void) | |
88 { | |
89 ngx_pcre_pool = NULL; | |
90 } | |
91 | |
92 | |
93 ngx_int_t | |
94 ngx_regex_compile(ngx_regex_compile_t *rc) | |
95 { | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
96 int n, erroff; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
97 char *p; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
98 pcre *re; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
99 const char *errstr; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
100 ngx_regex_elt_t *elt; |
3325 | 101 |
102 ngx_regex_malloc_init(rc->pool); | |
103 | |
104 re = pcre_compile((const char *) rc->pattern.data, (int) rc->options, | |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
216
diff
changeset
|
105 &errstr, &erroff, NULL); |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 |
3325 | 107 /* ensure that there is no current pool */ |
108 ngx_regex_malloc_done(); | |
109 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 if (re == NULL) { |
3325 | 111 if ((size_t) erroff == rc->pattern.len) { |
112 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, | |
113 "pcre_compile() failed: %s in \"%V\"", | |
114 errstr, &rc->pattern) | |
115 - rc->err.data; | |
116 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 } else { |
3325 | 118 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
119 "pcre_compile() failed: %s in \"%V\" at \"%s\"", | |
120 errstr, &rc->pattern, rc->pattern.data + erroff) | |
121 - rc->err.data; | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 } |
3325 | 123 |
124 return NGX_ERROR; | |
125 } | |
126 | |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
127 rc->regex = ngx_pcalloc(rc->pool, sizeof(ngx_regex_t)); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
128 if (rc->regex == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
129 goto nomem; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
130 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
131 |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
132 rc->regex->code = re; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
133 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
134 /* do not study at runtime */ |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
135 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
136 if (ngx_pcre_studies != NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
137 elt = ngx_list_push(ngx_pcre_studies); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
138 if (elt == NULL) { |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
139 goto nomem; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
140 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
141 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
142 elt->regex = rc->regex; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
143 elt->name = rc->pattern.data; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
144 } |
3325 | 145 |
146 n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures); | |
147 if (n < 0) { | |
148 p = "pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d"; | |
149 goto failed; | |
150 } | |
151 | |
152 if (rc->captures == 0) { | |
153 return NGX_OK; | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 |
3325 | 156 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->named_captures); |
157 if (n < 0) { | |
158 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMECOUNT) failed: %d"; | |
159 goto failed; | |
160 } | |
161 | |
162 if (rc->named_captures == 0) { | |
163 return NGX_OK; | |
164 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
165 |
3325 | 166 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMEENTRYSIZE, &rc->name_size); |
167 if (n < 0) { | |
168 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMEENTRYSIZE) failed: %d"; | |
169 goto failed; | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
170 } |
3325 | 171 |
172 n = pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->names); | |
173 if (n < 0) { | |
174 p = "pcre_fullinfo(\"%V\", PCRE_INFO_NAMETABLE) failed: %d"; | |
175 goto failed; | |
176 } | |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
177 |
3325 | 178 return NGX_OK; |
179 | |
180 failed: | |
181 | |
182 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) | |
183 - rc->err.data; | |
5824
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
184 return NGX_ERROR; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
185 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
186 nomem: |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
187 |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
188 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
189 "regex \"%V\" compilation failed: no memory", |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
190 &rc->pattern) |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
191 - rc->err.data; |
e7f6991eca47
Core: ngx_regex_compile() error handling fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4638
diff
changeset
|
192 return NGX_ERROR; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 |
503 | 196 ngx_int_t |
1784 | 197 ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log) |
198 { | |
199 ngx_int_t n; | |
200 ngx_uint_t i; | |
201 ngx_regex_elt_t *re; | |
202 | |
203 re = a->elts; | |
204 | |
205 for (i = 0; i < a->nelts; i++) { | |
206 | |
207 n = ngx_regex_exec(re[i].regex, s, NULL, 0); | |
208 | |
209 if (n == NGX_REGEX_NO_MATCHED) { | |
210 continue; | |
211 } | |
212 | |
213 if (n < 0) { | |
214 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
3325 | 215 ngx_regex_exec_n " failed: %i on \"%V\" using \"%s\"", |
1784 | 216 n, s, re[i].name); |
217 return NGX_ERROR; | |
218 } | |
219 | |
220 /* match */ | |
221 | |
222 return NGX_OK; | |
223 } | |
224 | |
225 return NGX_DECLINED; | |
226 } | |
227 | |
228 | |
503 | 229 static void * ngx_libc_cdecl |
230 ngx_regex_malloc(size_t size) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 { |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
232 ngx_pool_t *pool; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
233 pool = ngx_pcre_pool; |
3325 | 234 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
235 if (pool) { |
2049 | 236 return ngx_palloc(pool, size); |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
237 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
238 |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
239 return NULL; |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
240 } |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 |
503 | 243 static void ngx_libc_cdecl |
244 ngx_regex_free(void *p) | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 { |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 return; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 } |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
248 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
249 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
250 static void |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
251 ngx_regex_cleanup(void *data) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
252 { |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
253 #if (NGX_HAVE_PCRE_JIT) |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
254 ngx_regex_conf_t *rcf = data; |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
255 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
256 ngx_uint_t i; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
257 ngx_list_part_t *part; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
258 ngx_regex_elt_t *elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
259 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
260 part = &rcf->studies->part; |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
261 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
262 |
7088 | 263 for (i = 0; /* void */ ; i++) { |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
264 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
265 if (i >= part->nelts) { |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
266 if (part->next == NULL) { |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
267 break; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
268 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
269 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
270 part = part->next; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
271 elts = part->elts; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
272 i = 0; |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
273 } |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
274 |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
275 /* |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
276 * The PCRE JIT compiler uses mmap for its executable codes, so we |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
277 * have to explicitly call the pcre_free_study() function to free |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
278 * this memory. |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
279 */ |
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
280 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
281 if (elts[i].regex->extra != NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
282 pcre_free_study(elts[i].regex->extra); |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
283 } |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
284 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
285 #endif |
4423
196c3dacff0d
Fixed memory leak on HUP signal when PCRE JIT was used.
Valentin Bartenev <vbart@nginx.com>
parents:
4413
diff
changeset
|
286 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
287 /* |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
288 * On configuration parsing errors ngx_regex_module_init() will not |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
289 * be called. Make sure ngx_pcre_studies is properly cleared anyway. |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
290 */ |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
291 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
292 ngx_pcre_studies = NULL; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
293 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
294 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
295 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
296 static ngx_int_t |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
297 ngx_regex_module_init(ngx_cycle_t *cycle) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
298 { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
299 int opt; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
300 const char *errstr; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
301 ngx_uint_t i; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
302 ngx_list_part_t *part; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
303 ngx_regex_elt_t *elts; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
304 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
305 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
306 opt = 0; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
307 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
308 rcf = (ngx_regex_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_regex_module); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
309 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
310 #if (NGX_HAVE_PCRE_JIT) |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
311 if (rcf->pcre_jit) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
312 opt = PCRE_STUDY_JIT_COMPILE; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
313 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
314 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
315 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
316 ngx_regex_malloc_init(cycle->pool); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
317 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
318 part = &rcf->studies->part; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
319 elts = part->elts; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
320 |
7088 | 321 for (i = 0; /* void */ ; i++) { |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
322 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
323 if (i >= part->nelts) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
324 if (part->next == NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
325 break; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
326 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
327 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
328 part = part->next; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
329 elts = part->elts; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
330 i = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
331 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
332 |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
333 elts[i].regex->extra = pcre_study(elts[i].regex->code, opt, &errstr); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
334 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
335 if (errstr != NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
336 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
337 "pcre_study() failed: %s in \"%s\"", |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
338 errstr, elts[i].name); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
339 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
340 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
341 #if (NGX_HAVE_PCRE_JIT) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
342 if (opt & PCRE_STUDY_JIT_COMPILE) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
343 int jit, n; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
344 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
345 jit = 0; |
4638
6e1a48bcf915
Fixed the ngx_regex.h header file compatibility with C++.
Valentin Bartenev <vbart@nginx.com>
parents:
4423
diff
changeset
|
346 n = pcre_fullinfo(elts[i].regex->code, elts[i].regex->extra, |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
347 PCRE_INFO_JIT, &jit); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
348 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
349 if (n != 0 || jit != 1) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
350 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
351 "JIT compiler does not support pattern: \"%s\"", |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
352 elts[i].name); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
353 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
354 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
355 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
356 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
357 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
358 ngx_regex_malloc_done(); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
359 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
360 ngx_pcre_studies = NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
361 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
362 return NGX_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
363 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
364 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
365 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
366 static void * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
367 ngx_regex_create_conf(ngx_cycle_t *cycle) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
368 { |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
369 ngx_regex_conf_t *rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
370 ngx_pool_cleanup_t *cln; |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
371 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
372 rcf = ngx_pcalloc(cycle->pool, sizeof(ngx_regex_conf_t)); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
373 if (rcf == NULL) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
374 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
375 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
376 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
377 rcf->pcre_jit = NGX_CONF_UNSET; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
378 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
379 cln = ngx_pool_cleanup_add(cycle->pool, 0); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
380 if (cln == NULL) { |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
381 return NULL; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
382 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
383 |
7978
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
384 cln->handler = ngx_regex_cleanup; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
385 cln->data = rcf; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
386 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
387 rcf->studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t)); |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
388 if (rcf->studies == NULL) { |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
389 return NULL; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
390 } |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
391 |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
392 ngx_pcre_studies = rcf->studies; |
2ca57257252d
Core: fixed ngx_pcre_studies cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7088
diff
changeset
|
393 |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
394 return rcf; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
395 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
396 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
397 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
398 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
399 ngx_regex_init_conf(ngx_cycle_t *cycle, void *conf) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
400 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
401 ngx_regex_conf_t *rcf = conf; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
402 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
403 ngx_conf_init_value(rcf->pcre_jit, 0); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
404 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
405 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
406 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
407 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
408 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
409 static char * |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
410 ngx_regex_pcre_jit(ngx_conf_t *cf, void *post, void *data) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
411 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
412 ngx_flag_t *fp = data; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
413 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
414 if (*fp == 0) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
415 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
416 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
417 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
418 #if (NGX_HAVE_PCRE_JIT) |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
419 { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
420 int jit, r; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
421 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
422 jit = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
423 r = pcre_config(PCRE_CONFIG_JIT, &jit); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
424 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
425 if (r != 0 || jit != 1) { |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
426 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
427 "PCRE library does not support JIT"); |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
428 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
429 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
430 } |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
431 #else |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
432 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
4413
23ea4e72c85a
Fixed grammar in PCRE JIT error log message.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
433 "nginx was built without PCRE JIT support"); |
4388
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
434 *fp = 0; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
435 #endif |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
436 |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
437 return NGX_CONF_OK; |
005fc2d5e84f
Added support for regex study and PCRE JIT (ticket #41) optimizations on
Valentin Bartenev <vbart@nginx.com>
parents:
4326
diff
changeset
|
438 } |