Bug Summary

File:core/ngx_module.c
Location:line 230, column 21
Description:Access to field 'name' results in a dereference of a null pointer

Annotated Source Code

1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Maxim Dounin
5 * Copyright (C) Nginx, Inc.
6 */
7
8
9#include <ngx_config.h>
10#include <ngx_core.h>
11
12
13#define NGX_MAX_DYNAMIC_MODULES128 128
14
15
16static ngx_uint_t ngx_module_index(ngx_cycle_t *cycle);
17static ngx_uint_t ngx_module_ctx_index(ngx_cycle_t *cycle, ngx_uint_t type,
18 ngx_uint_t index);
19
20
21ngx_uint_t ngx_max_module;
22static ngx_uint_t ngx_modules_n;
23
24
25ngx_int_t
26ngx_preinit_modules(void)
27{
28 ngx_uint_t i;
29
30 for (i = 0; ngx_modules[i]; i++) {
31 ngx_modules[i]->index = i;
32 ngx_modules[i]->name = ngx_module_names[i];
33 }
34
35 ngx_modules_n = i;
36 ngx_max_module = ngx_modules_n + NGX_MAX_DYNAMIC_MODULES128;
37
38 return NGX_OK0;
39}
40
41
42ngx_int_t
43ngx_cycle_modules(ngx_cycle_t *cycle)
44{
45 /*
46 * create a list of modules to be used for this cycle,
47 * copy static modules to it
48 */
49
50 cycle->modules = ngx_pcalloc(cycle->pool, (ngx_max_module + 1)
51 * sizeof(ngx_module_t *));
52 if (cycle->modules == NULL((void*)0)) {
53 return NGX_ERROR-1;
54 }
55
56 ngx_memcpy(cycle->modules, ngx_modules,(void) memcpy(cycle->modules, ngx_modules, ngx_modules_n *
sizeof(ngx_module_t *))
57 ngx_modules_n * sizeof(ngx_module_t *))(void) memcpy(cycle->modules, ngx_modules, ngx_modules_n *
sizeof(ngx_module_t *))
;
58
59 cycle->modules_n = ngx_modules_n;
60
61 return NGX_OK0;
62}
63
64
65ngx_int_t
66ngx_init_modules(ngx_cycle_t *cycle)
67{
68 ngx_uint_t i;
69
70 for (i = 0; cycle->modules[i]; i++) {
71 if (cycle->modules[i]->init_module) {
72 if (cycle->modules[i]->init_module(cycle) != NGX_OK0) {
73 return NGX_ERROR-1;
74 }
75 }
76 }
77
78 return NGX_OK0;
79}
80
81
82ngx_int_t
83ngx_count_modules(ngx_cycle_t *cycle, ngx_uint_t type)
84{
85 ngx_uint_t i, next, max;
86 ngx_module_t *module;
87
88 next = 0;
89 max = 0;
90
91 /* count appropriate modules, set up their indices */
92
93 for (i = 0; cycle->modules[i]; i++) {
94 module = cycle->modules[i];
95
96 if (module->type != type) {
97 continue;
98 }
99
100 if (module->ctx_index != NGX_MODULE_UNSET_INDEX(ngx_uint_t) -1) {
101
102 /* if ctx_index was assigned, preserve it */
103
104 if (module->ctx_index > max) {
105 max = module->ctx_index;
106 }
107
108 if (module->ctx_index == next) {
109 next++;
110 }
111
112 continue;
113 }
114
115 /* search for some free index */
116
117 module->ctx_index = ngx_module_ctx_index(cycle, type, next);
118
119 if (module->ctx_index > max) {
120 max = module->ctx_index;
121 }
122
123 next = module->ctx_index + 1;
124 }
125
126 /*
127 * make sure the number returned is big enough for previous
128 * cycle as well, else there will be problems if the number
129 * will be stored in a global variable (as it's used to be)
130 * and we'll have to roll back to the previous cycle
131 */
132
133 if (cycle->old_cycle && cycle->old_cycle->modules) {
134
135 for (i = 0; cycle->old_cycle->modules[i]; i++) {
136 module = cycle->old_cycle->modules[i];
137
138 if (module->type != type) {
139 continue;
140 }
141
142 if (module->ctx_index > max) {
143 max = module->ctx_index;
144 }
145 }
146 }
147
148 /* prevent loading of additional modules */
149
150 cycle->modules_used = 1;
151
152 return max + 1;
153}
154
155
156ngx_int_t
157ngx_add_module(ngx_conf_t *cf, ngx_str_t *file, ngx_module_t *module,
158 char **order)
159{
160 void *rv;
161 ngx_uint_t i, m, before;
162 ngx_core_module_t *core_module;
163
164 if (cf->cycle->modules_n >= ngx_max_module) {
1
Taking false branch
165 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
166 "too many modules loaded");
167 return NGX_ERROR-1;
168 }
169
170 if (module->version != nginx_version1011001) {
2
Taking false branch
171 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
172 "module \"%V\" version %ui instead of %ui",
173 file, module->version, (ngx_uint_t) nginx_version1011001);
174 return NGX_ERROR-1;
175 }
176
177 if (ngx_strcmp(module->signature, NGX_MODULE_SIGNATURE)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) module->signature) && __builtin_constant_p
((const char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1"
"1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0"
"1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1") && (__s1_len
= strlen ((const char *) module->signature), __s2_len = strlen
((const char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1"
"1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0"
"1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1"), (!((size_t)(const
void *)(((const char *) module->signature) + 1) - (size_t
)(const void *)((const char *) module->signature) == 1) ||
__s1_len >= 4) && (!((size_t)(const void *)(((const
char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0"
"0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0"
"0" "1" "0" "1" "0" "0" "0" "1" "1") + 1) - (size_t)(const void
*)((const char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1"
"1" "1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1"
"0" "1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1") == 1) || __s2_len
>= 4)) ? __builtin_strcmp ((const char *) module->signature
, (const char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1"
"1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0"
"1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1") : (__builtin_constant_p
((const char *) module->signature) && ((size_t)(const
void *)(((const char *) module->signature) + 1) - (size_t
)(const void *)((const char *) module->signature) == 1) &&
(__s1_len = strlen ((const char *) module->signature), __s1_len
< 4) ? (__builtin_constant_p ((const char *) "8" "," "4" ","
"8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0" "1" "0" "1" "0" "1"
"1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0" "1" "0" "1" "0" "0"
"0" "1" "1") && ((size_t)(const void *)(((const char
*) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0"
"1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0"
"1" "0" "1" "0" "0" "0" "1" "1") + 1) - (size_t)(const void *
)((const char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1"
"1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0"
"1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1") == 1) ? __builtin_strcmp
((const char *) module->signature, (const char *) "8" ","
"4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0" "1" "0" "1"
"0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0" "1" "0" "1"
"0" "0" "0" "1" "1") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ((const char *
) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0"
"1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0"
"1" "0" "1" "0" "0" "0" "1" "1"); int __result = (((const unsigned
char *) (const char *) ((const char *) module->signature)
)[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) module->signature))[1] - __s2[1]); if (__s1_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) module->signature))[2] -
__s2[2]); if (__s1_len > 2 && __result == 0) __result
= (((const unsigned char *) (const char *) ((const char *) module
->signature))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
((const char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1"
"1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0"
"1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1") && ((size_t
)(const void *)(((const char *) "8" "," "4" "," "8" "," "0" "0"
"0" "0" "1" "1" "1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1"
"1" "1" "1" "0" "1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1")
+ 1) - (size_t)(const void *)((const char *) "8" "," "4" ","
"8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0" "1" "0" "1" "0" "1"
"1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0" "1" "0" "1" "0" "0"
"0" "1" "1") == 1) && (__s2_len = strlen ((const char
*) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0"
"1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0"
"1" "0" "1" "0" "0" "0" "1" "1"), __s2_len < 4) ? (__builtin_constant_p
((const char *) module->signature) && ((size_t)(const
void *)(((const char *) module->signature) + 1) - (size_t
)(const void *)((const char *) module->signature) == 1) ? __builtin_strcmp
((const char *) module->signature, (const char *) "8" ","
"4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0" "1" "0" "1"
"0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0" "1" "0" "1"
"0" "0" "0" "1" "1") : (- (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ((const char *
) module->signature); int __result = (((const unsigned char
*) (const char *) ((const char *) "8" "," "4" "," "8" "," "0"
"0" "0" "0" "1" "1" "1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1"
"1" "1" "1" "1" "0" "1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0"
"0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0"
"0" "1" "0" "1" "0" "0" "0" "1" "1"))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) ((const char *) "8" "," "4" "," "8" ","
"0" "0" "0" "0" "1" "1" "1" "0" "0" "1" "0" "1" "0" "1" "1" "1"
"1" "1" "1" "1" "1" "0" "1" "0" "0" "1" "0" "1" "0" "0" "0" "1"
"1"))[2] - __s2[2]); if (__s2_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) "8" "," "4" "," "8" "," "0" "0" "0" "0" "1" "1"
"1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0"
"1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1"))[3] - __s2[3]);
} } __result; })))) : __builtin_strcmp ((const char *) module
->signature, (const char *) "8" "," "4" "," "8" "," "0" "0"
"0" "0" "1" "1" "1" "0" "0" "1" "0" "1" "0" "1" "1" "1" "1" "1"
"1" "1" "1" "0" "1" "0" "0" "1" "0" "1" "0" "0" "0" "1" "1")
))); })
!= 0) {
3
Taking false branch
178 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
179 "module \"%V\" is not binary compatible",
180 file);
181 return NGX_ERROR-1;
182 }
183
184 for (m = 0; cf->cycle->modules[m]; m++) {
4
Assuming pointer value is null
5
Loop condition is false. Execution continues on line 197
185 if (ngx_strcmp(cf->cycle->modules[m]->name, module->name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) cf->cycle->modules[m]->name) &&
__builtin_constant_p ((const char *) module->name) &&
(__s1_len = strlen ((const char *) cf->cycle->modules[
m]->name), __s2_len = strlen ((const char *) module->name
), (!((size_t)(const void *)(((const char *) cf->cycle->
modules[m]->name) + 1) - (size_t)(const void *)((const char
*) cf->cycle->modules[m]->name) == 1) || __s1_len >=
4) && (!((size_t)(const void *)(((const char *) module
->name) + 1) - (size_t)(const void *)((const char *) module
->name) == 1) || __s2_len >= 4)) ? __builtin_strcmp ((const
char *) cf->cycle->modules[m]->name, (const char *)
module->name) : (__builtin_constant_p ((const char *) cf->
cycle->modules[m]->name) && ((size_t)(const void
*)(((const char *) cf->cycle->modules[m]->name) + 1
) - (size_t)(const void *)((const char *) cf->cycle->modules
[m]->name) == 1) && (__s1_len = strlen ((const char
*) cf->cycle->modules[m]->name), __s1_len < 4) ?
(__builtin_constant_p ((const char *) module->name) &&
((size_t)(const void *)(((const char *) module->name) + 1
) - (size_t)(const void *)((const char *) module->name) ==
1) ? __builtin_strcmp ((const char *) cf->cycle->modules
[m]->name, (const char *) module->name) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) module->name); int __result = (((
const unsigned char *) (const char *) ((const char *) cf->
cycle->modules[m]->name))[0] - __s2[0]); if (__s1_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) cf->cycle->modules[m
]->name))[1] - __s2[1]); if (__s1_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) cf->cycle->modules[m]->name))[2] - __s2
[2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) ((const char *) cf->
cycle->modules[m]->name))[3] - __s2[3]); } } __result; }
))) : (__builtin_constant_p ((const char *) module->name) &&
((size_t)(const void *)(((const char *) module->name) + 1
) - (size_t)(const void *)((const char *) module->name) ==
1) && (__s2_len = strlen ((const char *) module->
name), __s2_len < 4) ? (__builtin_constant_p ((const char *
) cf->cycle->modules[m]->name) && ((size_t)(
const void *)(((const char *) cf->cycle->modules[m]->
name) + 1) - (size_t)(const void *)((const char *) cf->cycle
->modules[m]->name) == 1) ? __builtin_strcmp ((const char
*) cf->cycle->modules[m]->name, (const char *) module
->name) : (- (__extension__ ({ const unsigned char *__s2 =
(const unsigned char *) (const char *) ((const char *) cf->
cycle->modules[m]->name); int __result = (((const unsigned
char *) (const char *) ((const char *) module->name))[0] -
__s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) module
->name))[1] - __s2[1]); if (__s2_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) module->name))[2] - __s2[2]); if (__s2_len >
2 && __result == 0) __result = (((const unsigned char
*) (const char *) ((const char *) module->name))[3] - __s2
[3]); } } __result; })))) : __builtin_strcmp ((const char *) cf
->cycle->modules[m]->name, (const char *) module->
name)))); })
== 0) {
186 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
187 "module \"%s\" is already loaded",
188 module->name);
189 return NGX_ERROR-1;
190 }
191 }
192
193 /*
194 * if the module wasn't previously loaded, assign an index
195 */
196
197 if (module->index == NGX_MODULE_UNSET_INDEX(ngx_uint_t) -1) {
6
Taking false branch
198 module->index = ngx_module_index(cf->cycle);
199
200 if (module->index >= ngx_max_module) {
201 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
202 "too many modules loaded");
203 return NGX_ERROR-1;
204 }
205 }
206
207 /*
208 * put the module into the cycle->modules array
209 */
210
211 before = cf->cycle->modules_n;
212
213 if (order) {
7
Assuming 'order' is non-null
8
Taking true branch
214 for (i = 0; order[i]; i++) {
9
Loop condition is true. Entering loop body
215 if (ngx_strcmp(order[i], module->name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) order[i]) && __builtin_constant_p ((
const char *) module->name) && (__s1_len = strlen (
(const char *) order[i]), __s2_len = strlen ((const char *) module
->name), (!((size_t)(const void *)(((const char *) order[i
]) + 1) - (size_t)(const void *)((const char *) order[i]) == 1
) || __s1_len >= 4) && (!((size_t)(const void *)((
(const char *) module->name) + 1) - (size_t)(const void *)
((const char *) module->name) == 1) || __s2_len >= 4)) ?
__builtin_strcmp ((const char *) order[i], (const char *) module
->name) : (__builtin_constant_p ((const char *) order[i]) &&
((size_t)(const void *)(((const char *) order[i]) + 1) - (size_t
)(const void *)((const char *) order[i]) == 1) && (__s1_len
= strlen ((const char *) order[i]), __s1_len < 4) ? (__builtin_constant_p
((const char *) module->name) && ((size_t)(const void
*)(((const char *) module->name) + 1) - (size_t)(const void
*)((const char *) module->name) == 1) ? __builtin_strcmp (
(const char *) order[i], (const char *) module->name) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) module->name); int __result = (((
const unsigned char *) (const char *) ((const char *) order[i
]))[0] - __s2[0]); if (__s1_len > 0 && __result ==
0) { __result = (((const unsigned char *) (const char *) ((const
char *) order[i]))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ((const char *) order[i]))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ((const char *) order[i]))[3] - __s2[
3]); } } __result; }))) : (__builtin_constant_p ((const char *
) module->name) && ((size_t)(const void *)(((const
char *) module->name) + 1) - (size_t)(const void *)((const
char *) module->name) == 1) && (__s2_len = strlen
((const char *) module->name), __s2_len < 4) ? (__builtin_constant_p
((const char *) order[i]) && ((size_t)(const void *)
(((const char *) order[i]) + 1) - (size_t)(const void *)((const
char *) order[i]) == 1) ? __builtin_strcmp ((const char *) order
[i], (const char *) module->name) : (- (__extension__ ({ const
unsigned char *__s2 = (const unsigned char *) (const char *)
((const char *) order[i]); int __result = (((const unsigned char
*) (const char *) ((const char *) module->name))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) module
->name))[1] - __s2[1]); if (__s2_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) module->name))[2] - __s2[2]); if (__s2_len >
2 && __result == 0) __result = (((const unsigned char
*) (const char *) ((const char *) module->name))[3] - __s2
[3]); } } __result; })))) : __builtin_strcmp ((const char *) order
[i], (const char *) module->name)))); })
== 0) {
10
Taking true branch
216 i++;
217 break;
11
Execution continues on line 221
218 }
219 }
220
221 for ( /* void */ ; order[i]; i++) {
12
Loop condition is true. Entering loop body
222
223#if 0
224 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cf->log, 0,
225 "module: %s before %s",
226 module->name, order[i]);
227#endif
228
229 for (m = 0; m < before; m++) {
13
Assuming 'm' is < 'before'
14
Loop condition is true. Entering loop body
230 if (ngx_strcmp(cf->cycle->modules[m]->name, order[i])__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) cf->cycle->modules[m]->name) &&
__builtin_constant_p ((const char *) order[i]) && (__s1_len
= strlen ((const char *) cf->cycle->modules[m]->name
), __s2_len = strlen ((const char *) order[i]), (!((size_t)(const
void *)(((const char *) cf->cycle->modules[m]->name
) + 1) - (size_t)(const void *)((const char *) cf->cycle->
modules[m]->name) == 1) || __s1_len >= 4) && (!
((size_t)(const void *)(((const char *) order[i]) + 1) - (size_t
)(const void *)((const char *) order[i]) == 1) || __s2_len >=
4)) ? __builtin_strcmp ((const char *) cf->cycle->modules
[m]->name, (const char *) order[i]) : (__builtin_constant_p
((const char *) cf->cycle->modules[m]->name) &&
((size_t)(const void *)(((const char *) cf->cycle->modules
[m]->name) + 1) - (size_t)(const void *)((const char *) cf
->cycle->modules[m]->name) == 1) && (__s1_len
= strlen ((const char *) cf->cycle->modules[m]->name
), __s1_len < 4) ? (__builtin_constant_p ((const char *) order
[i]) && ((size_t)(const void *)(((const char *) order
[i]) + 1) - (size_t)(const void *)((const char *) order[i]) ==
1) ? __builtin_strcmp ((const char *) cf->cycle->modules
[m]->name, (const char *) order[i]) : (__extension__ ({ const
unsigned char *__s2 = (const unsigned char *) (const char *)
((const char *) order[i]); int __result = (((const unsigned char
*) (const char *) ((const char *) cf->cycle->modules[m
]->name))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) cf->cycle->modules[m]->name))[1] - __s2
[1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) cf
->cycle->modules[m]->name))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ((const char *) cf->cycle->modules
[m]->name))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
((const char *) order[i]) && ((size_t)(const void *)
(((const char *) order[i]) + 1) - (size_t)(const void *)((const
char *) order[i]) == 1) && (__s2_len = strlen ((const
char *) order[i]), __s2_len < 4) ? (__builtin_constant_p (
(const char *) cf->cycle->modules[m]->name) &&
((size_t)(const void *)(((const char *) cf->cycle->modules
[m]->name) + 1) - (size_t)(const void *)((const char *) cf
->cycle->modules[m]->name) == 1) ? __builtin_strcmp (
(const char *) cf->cycle->modules[m]->name, (const char
*) order[i]) : (- (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ((const char *) cf->
cycle->modules[m]->name); int __result = (((const unsigned
char *) (const char *) ((const char *) order[i]))[0] - __s2[
0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) order
[i]))[1] - __s2[1]); if (__s2_len > 1 && __result ==
0) { __result = (((const unsigned char *) (const char *) ((const
char *) order[i]))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) order[i]))[3] - __s2[3]); } } __result; }
)))) : __builtin_strcmp ((const char *) cf->cycle->modules
[m]->name, (const char *) order[i])))); })
== 0) {
15
Within the expansion of the macro 'ngx_strcmp':
a
Access to field 'name' results in a dereference of a null pointer
231
232 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cf->log, 0,
233 "module: %s before %s:%i",
234 module->name, order[i], m);
235
236 before = m;
237 break;
238 }
239 }
240 }
241 }
242
243 /* put the module before modules[before] */
244
245 if (before != cf->cycle->modules_n) {
246 ngx_memmove(&cf->cycle->modules[before + 1],(void) memmove(&cf->cycle->modules[before + 1], &
cf->cycle->modules[before], (cf->cycle->modules_n
- before) * sizeof(ngx_module_t *))
247 &cf->cycle->modules[before],(void) memmove(&cf->cycle->modules[before + 1], &
cf->cycle->modules[before], (cf->cycle->modules_n
- before) * sizeof(ngx_module_t *))
248 (cf->cycle->modules_n - before) * sizeof(ngx_module_t *))(void) memmove(&cf->cycle->modules[before + 1], &
cf->cycle->modules[before], (cf->cycle->modules_n
- before) * sizeof(ngx_module_t *))
;
249 }
250
251 cf->cycle->modules[before] = module;
252 cf->cycle->modules_n++;
253
254 if (module->type == NGX_CORE_MODULE0x45524F43) {
255
256 /*
257 * we are smart enough to initialize core modules;
258 * other modules are expected to be loaded before
259 * initialization - e.g., http modules must be loaded
260 * before http{} block
261 */
262
263 core_module = module->ctx;
264
265 if (core_module->create_conf) {
266 rv = core_module->create_conf(cf->cycle);
267 if (rv == NULL((void*)0)) {
268 return NGX_ERROR-1;
269 }
270
271 cf->cycle->conf_ctx[module->index] = rv;
272 }
273 }
274
275 return NGX_OK0;
276}
277
278
279static ngx_uint_t
280ngx_module_index(ngx_cycle_t *cycle)
281{
282 ngx_uint_t i, index;
283 ngx_module_t *module;
284
285 index = 0;
286
287again:
288
289 /* find an unused index */
290
291 for (i = 0; cycle->modules[i]; i++) {
292 module = cycle->modules[i];
293
294 if (module->index == index) {
295 index++;
296 goto again;
297 }
298 }
299
300 /* check previous cycle */
301
302 if (cycle->old_cycle && cycle->old_cycle->modules) {
303
304 for (i = 0; cycle->old_cycle->modules[i]; i++) {
305 module = cycle->old_cycle->modules[i];
306
307 if (module->index == index) {
308 index++;
309 goto again;
310 }
311 }
312 }
313
314 return index;
315}
316
317
318static ngx_uint_t
319ngx_module_ctx_index(ngx_cycle_t *cycle, ngx_uint_t type, ngx_uint_t index)
320{
321 ngx_uint_t i;
322 ngx_module_t *module;
323
324again:
325
326 /* find an unused ctx_index */
327
328 for (i = 0; cycle->modules[i]; i++) {
329 module = cycle->modules[i];
330
331 if (module->type != type) {
332 continue;
333 }
334
335 if (module->ctx_index == index) {
336 index++;
337 goto again;
338 }
339 }
340
341 /* check previous cycle */
342
343 if (cycle->old_cycle && cycle->old_cycle->modules) {
344
345 for (i = 0; cycle->old_cycle->modules[i]; i++) {
346 module = cycle->old_cycle->modules[i];
347
348 if (module->type != type) {
349 continue;
350 }
351
352 if (module->ctx_index == index) {
353 index++;
354 goto again;
355 }
356 }
357 }
358
359 return index;
360}