Skip to content

Commit becbbe0

Browse files
committed
🐛 Compatible with lower versions of gcc.
1 parent e9a2ba0 commit becbbe0

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

inc/ngx_http_waf_module_check.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ static ngx_int_t ngx_http_waf_handler_check_white_url(ngx_http_request_t* r, ngx
383383
"ngx_waf_debug: The Inspection is skipped because the URL is empty.");
384384
ret_value = NOT_MATCHED;
385385
} else {
386-
for (size_t i = 0; i < srv_conf->white_url->nelts; i++, p++) {
386+
size_t i;
387+
for (i = 0; i < srv_conf->white_url->nelts; i++, p++) {
387388
ngx_int_t rc = ngx_regex_exec(p->regex, p_uri, NULL, 0);
388389
if (rc >= 0) {
389390
ctx->blocked = FALSE;
@@ -436,7 +437,8 @@ static ngx_int_t ngx_http_waf_handler_check_black_url(ngx_http_request_t* r, ngx
436437
"ngx_waf_debug: The Inspection is skipped because the URL is empty.");
437438
ret_value = NOT_MATCHED;
438439
} else {
439-
for (size_t i = 0; i < srv_conf->black_url->nelts; i++, p++) {
440+
size_t i;
441+
for (i = 0; i < srv_conf->black_url->nelts; i++, p++) {
440442
ngx_int_t rc = ngx_regex_exec(p->regex, p_uri, NULL, 0);
441443
if (rc >= 0) {
442444
ctx->blocked = TRUE;
@@ -493,7 +495,8 @@ static ngx_int_t ngx_http_waf_handler_check_black_args(ngx_http_request_t* r, ng
493495
"ngx_waf_debug: The Inspection is skipped because the ARGS is empty.");
494496
ret_value = NOT_MATCHED;
495497
} else {
496-
for (size_t i = 0; i < srv_conf->black_args->nelts; i++, p++) {
498+
size_t i;
499+
for (i = 0; i < srv_conf->black_args->nelts; i++, p++) {
497500
ngx_int_t rc = ngx_regex_exec(p->regex, p_args, NULL, 0);
498501
if (rc >= 0) {
499502
ctx->blocked = TRUE;
@@ -550,7 +553,8 @@ static ngx_int_t ngx_http_waf_handler_check_black_user_agent(ngx_http_request_t*
550553
"ngx_waf_debug: The Inspection is skipped because the User-Agent is empty.");
551554
ret_value = NOT_MATCHED;
552555
} else {
553-
for (size_t i = 0; i < srv_conf->black_ua->nelts; i++, p++) {
556+
size_t i;
557+
for (i = 0; i < srv_conf->black_ua->nelts; i++, p++) {
554558
ngx_int_t rc = ngx_regex_exec(p->regex, p_ua, NULL, 0);
555559
if (rc >= 0) {
556560
ctx->blocked = TRUE;
@@ -607,7 +611,8 @@ static ngx_int_t ngx_http_waf_handler_check_white_referer(ngx_http_request_t* r,
607611
"ngx_waf_debug: The Inspection is skipped because the Referer is empty.");
608612
ret_value = NOT_MATCHED;
609613
} else {
610-
for (size_t i = 0; i < srv_conf->white_referer->nelts; i++, p++) {
614+
size_t i;
615+
for (i = 0; i < srv_conf->white_referer->nelts; i++, p++) {
611616
ngx_int_t rc = ngx_regex_exec(p->regex, p_referer, NULL, 0);
612617
if (rc >= 0) {
613618
ctx->blocked = FALSE;
@@ -664,7 +669,8 @@ static ngx_int_t ngx_http_waf_handler_check_black_referer(ngx_http_request_t* r,
664669
"ngx_waf_debug: The Inspection is skipped because the Referer is empty.");
665670
ret_value = NOT_MATCHED;
666671
} else {
667-
for (size_t i = 0; i < srv_conf->black_referer->nelts; i++, p++) {
672+
size_t i;
673+
for (i = 0; i < srv_conf->black_referer->nelts; i++, p++) {
668674
ngx_int_t rc = ngx_regex_exec(p->regex, p_referer, NULL, 0);
669675
if (rc >= 0) {
670676
ctx->blocked = FALSE;
@@ -710,9 +716,11 @@ static ngx_int_t ngx_http_waf_handler_check_black_cookie(ngx_http_request_t* r,
710716
"ngx_waf_debug: Inspection has begun.");
711717

712718
ngx_table_elt_t** ppcookie = r->headers_in.cookies.elts;
713-
for (size_t i = 0; i < r->headers_in.cookies.nelts; i++, ppcookie++) {
719+
size_t i;
720+
for (i = 0; i < r->headers_in.cookies.nelts; i++, ppcookie++) {
714721
ngx_regex_elt_t* p = srv_conf->black_cookie->elts;
715-
for (size_t j = 0; j < srv_conf->black_cookie->nelts; j++, p++) {
722+
size_t j;
723+
for (j = 0; j < srv_conf->black_cookie->nelts; j++, p++) {
716724
if ((**ppcookie).value.data == NULL || (**ppcookie).value.len == 0) {
717725
ngx_log_debug(NGX_LOG_DEBUG_CORE, r->connection->log, 0,
718726
"ngx_waf_debug: The Inspection is skipped because the Cookie.value is empty.");
@@ -800,7 +808,8 @@ static void check_post(ngx_http_request_t* r) {
800808

801809
ngx_regex_elt_t* p = srv_conf->black_post->elts;
802810
ngx_int_t rc;
803-
for (size_t i = 0; i < srv_conf->black_post->nelts; i++, p++) {
811+
size_t i;
812+
for (i = 0; i < srv_conf->black_post->nelts; i++, p++) {
804813
rc = ngx_regex_exec(p->regex, &body_str, NULL, 0);
805814
if (rc >= 0) {
806815
ctx->blocked = TRUE;

inc/ngx_http_waf_module_config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ static char* ngx_http_waf_rule_path_conf(ngx_conf_t* cf, ngx_command_t* cmd, voi
151151
static char* ngx_http_waf_mode_conf(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
152152
ngx_http_waf_srv_conf_t* srv_conf = (ngx_http_waf_srv_conf_t*)conf;
153153
ngx_str_t* modes = cf->args->elts;
154+
size_t i;
154155

155-
for (size_t i = 1; i < cf->args->nelts && modes != NULL; i++) {
156+
for (i = 1; i < cf->args->nelts && modes != NULL; i++) {
156157
if (ngx_strncasecmp(modes[i].data, (u_char*)"GET", min(modes[i].len, 5)) == 0) {
157158
srv_conf->waf_mode |= MODE_INSPECT_GET;
158159
}

inc/ngx_http_waf_module_util.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,16 @@ static ngx_int_t parse_ipv4(ngx_str_t text, ipv4_t* ipv4) {
123123
suffix_num = suffix;
124124

125125
uint8_t temp_suffix[4] = { 0 };
126-
for (int i = 0; i < 4; i++) {
126+
int i;
127+
for (i = 0; i < 4; i++) {
127128
uint8_t temp = 0;
128129
if (suffix >= 8) {
129130
suffix -=8;
130131
temp = ~0;
131132
}
132133
else {
133-
for (uint32_t j = 0; j < suffix; j++) {
134+
uint32_t j;
135+
for (j = 0; j < suffix; j++) {
134136
temp |= 0x80 >> j;
135137
}
136138
suffix = 0;
@@ -139,7 +141,7 @@ static ngx_int_t parse_ipv4(ngx_str_t text, ipv4_t* ipv4) {
139141
}
140142

141143
suffix = 0;
142-
for (int i = 0; i < 4; i++) {
144+
for (i = 0; i < 4; i++) {
143145
suffix |= ((uint32_t)temp_suffix[i]) << (i * 8);
144146
}
145147

@@ -203,23 +205,24 @@ static ngx_int_t parse_ipv6(ngx_str_t text, ipv6_t* ipv6) {
203205
}
204206

205207
suffix_num = temp_suffix;
206-
207-
for (int i = 0; i < 16; i++) {
208+
int i;
209+
for (i = 0; i < 16; i++) {
208210
uint8_t temp = 0;
209211
if (temp_suffix >= 8) {
210212
temp_suffix -=8;
211213
temp = ~0;
212214
}
213215
else {
214-
for (uint32_t j = 0; j < temp_suffix; j++) {
216+
uint32_t j;
217+
for (j = 0; j < temp_suffix; j++) {
215218
temp |= 0x80 >> j;
216219
}
217220
temp_suffix = 0;
218221
}
219222
suffix[i] = temp;
220223
}
221224

222-
for (int i = 0; i < 16; i++) {
225+
for (i = 0; i < 16; i++) {
223226
prefix[i] &= suffix[i];
224227
}
225228

src/ngx_http_waf_module_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ static ngx_int_t ngx_http_waf_handler_url_args(ngx_http_request_t* r) {
120120
http_status = NGX_DECLINED;
121121
}
122122
else {
123-
for (size_t i = 0; check_proc[i] != NULL; i++) {
123+
size_t i;
124+
for (i = 0; check_proc[i] != NULL; i++) {
124125
is_matched = check_proc[i](r, &http_status);
125126
if (is_matched == MATCHED) {
126127
break;
@@ -185,7 +186,8 @@ static ngx_int_t ngx_http_waf_handler_ip_url_referer_ua_args_cookie_post(ngx_htt
185186
http_status = NGX_DECLINED;
186187
}
187188
else {
188-
for (size_t i = 0; check_proc[i] != NULL; i++) {
189+
size_t i;
190+
for (i = 0; check_proc[i] != NULL; i++) {
189191
is_matched = check_proc[i](r, &http_status);
190192
if (is_matched == MATCHED) {
191193
break;

0 commit comments

Comments
 (0)