Skip to content

Commit 2fe3832

Browse files
authored
Merge pull request #3493 from umprayz/v2/cppcheck_nginx
fix: cppcheck warnings in nginx/
2 parents 630dfbd + 73f59fe commit 2fe3832

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ cppcheck:
5858
--inconclusive \
5959
--template="warning: {file},{line},{severity},{id},{message}" \
6060
--error-exitcode=1 \
61-
standalone/
61+
standalone/ \
62+
nginx/
6263

6364
check-static: cppcheck
6465

nginx/modsecurity/apr_bucket_nginx.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@ static apr_status_t nginx_bucket_read(apr_bucket *b, const char **str,
5454
apr_bucket_nginx *n = b->data;
5555
ngx_buf_t *buf = n->buf;
5656
u_char *data;
57-
ssize_t size;
5857

5958
if (buf->pos == NULL && ngx_buf_size(buf) != 0) {
6059
data = apr_bucket_alloc(ngx_buf_size(buf), b->list);
6160
if (data == NULL) {
6261
return APR_EGENERAL;
6362
}
6463

65-
size = ngx_read_file(buf->file, data, ngx_buf_size(buf), buf->file_pos);
64+
ssize_t size = ngx_read_file(buf->file, data, ngx_buf_size(buf), buf->file_pos);
6665
if (size != ngx_buf_size(buf)) {
6766
apr_bucket_free(data);
6867
return APR_EGENERAL;
@@ -80,9 +79,9 @@ static apr_status_t nginx_bucket_read(apr_bucket *b, const char **str,
8079
static void nginx_bucket_destroy(void *data)
8180
{
8281
apr_bucket_nginx *n = data;
83-
ngx_buf_t *buf = n->buf;
8482

8583
if (apr_bucket_shared_destroy(n)) {
84+
ngx_buf_t *buf = n->buf;
8685
if (!ngx_buf_in_memory(buf) && buf->pos != NULL) {
8786
apr_bucket_free(buf->pos);
8887
buf->pos = NULL;
@@ -92,8 +91,7 @@ static void nginx_bucket_destroy(void *data)
9291
}
9392

9493
ngx_buf_t * apr_bucket_to_ngx_buf(apr_bucket *e, ngx_pool_t *pool) {
95-
ngx_buf_t *buf, *b;
96-
apr_bucket_nginx *n;
94+
ngx_buf_t *buf;
9795
ngx_uint_t len;
9896
u_char *data;
9997

@@ -102,8 +100,8 @@ ngx_buf_t * apr_bucket_to_ngx_buf(apr_bucket *e, ngx_pool_t *pool) {
102100
}
103101

104102
if (e->type == &apr_bucket_type_nginx) {
105-
n = e->data;
106-
b = n->buf;
103+
apr_bucket_nginx *n = e->data;
104+
ngx_buf_t *b = n->buf;
107105

108106
/* whole buf */
109107
if (e->length == (apr_size_t)ngx_buf_size(b)) {
@@ -156,7 +154,6 @@ ngx_buf_t * apr_bucket_to_ngx_buf(apr_bucket *e, ngx_pool_t *pool) {
156154
ngx_int_t
157155
move_chain_to_brigade(ngx_chain_t *chain, apr_bucket_brigade *bb, ngx_pool_t *pool, ngx_int_t last_buf) {
158156
apr_bucket *e;
159-
ngx_chain_t *cl;
160157

161158
while (chain) {
162159
e = ngx_buf_to_apr_bucket(chain->buf, bb->p, bb->bucket_alloc);
@@ -171,7 +168,7 @@ move_chain_to_brigade(ngx_chain_t *chain, apr_bucket_brigade *bb, ngx_pool_t *po
171168
chain->buf->last_buf = 0;
172169
return NGX_OK;
173170
}
174-
cl = chain;
171+
ngx_chain_t *cl = chain;
175172
chain = chain->next;
176173
ngx_free_chain(pool, cl);
177174
}

nginx/modsecurity/ngx_http_modsecurity.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
8181
|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
8282
ngx_http_modsecurity_enable,
8383
NGX_HTTP_LOC_CONF_OFFSET,
84-
offsetof(ngx_http_modsecurity_loc_conf_t, enable),
84+
offsetof(ngx_http_modsecurity_loc_conf_t, enable), // cppcheck-suppress syntaxError
8585
NULL },
8686
ngx_null_command
8787
};
@@ -210,9 +210,9 @@ ngx_http_modsecurity_load_request(ngx_http_request_t *r)
210210
size_t root;
211211
ngx_str_t path;
212212
ngx_uint_t port;
213-
struct sockaddr_in *sin;
213+
const struct sockaddr_in *sin;
214214
#if (NGX_HAVE_INET6)
215-
struct sockaddr_in6 *sin6;
215+
const struct sockaddr_in6 *sin6;
216216
#endif
217217

218218
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity);
@@ -616,11 +616,9 @@ ngx_http_modsecurity_load_headers_out(ngx_http_request_t *r)
616616
ngx_http_modsecurity_ctx_t *ctx;
617617
char *data;
618618
request_rec *req;
619-
ngx_http_variable_value_t *vv;
620-
ngx_list_part_t *part;
619+
const ngx_list_part_t *part;
621620
ngx_table_elt_t *h;
622621
ngx_uint_t i;
623-
char *key, *value;
624622
u_char *buf = NULL;
625623
size_t size = 0;
626624

@@ -651,11 +649,11 @@ ngx_http_modsecurity_load_headers_out(ngx_http_request_t *r)
651649
return NGX_ERROR;
652650
}
653651

654-
key = (char *)buf;
652+
char *key = (char *)buf;
655653
buf = ngx_cpymem(buf, h[i].key.data, h[i].key.len);
656654
*buf++ = '\0';
657655

658-
value = (char *)buf;
656+
char *value = (char *)buf;
659657
buf = ngx_cpymem(buf, h[i].value.data, h[i].value.len);
660658
*buf++ = '\0';
661659

@@ -668,7 +666,7 @@ ngx_http_modsecurity_load_headers_out(ngx_http_request_t *r)
668666

669667
for (i = 0; special_headers_out[i].name; i++) {
670668

671-
vv = ngx_http_get_variable(r, &special_headers_out[i].variable_name,
669+
ngx_http_variable_value_t *vv = ngx_http_get_variable(r, &special_headers_out[i].variable_name,
672670
ngx_hash_key(special_headers_out[i].variable_name.data,
673671
special_headers_out[i].variable_name.len));
674672

@@ -892,7 +890,7 @@ modsec_pcre_malloc(size_t size)
892890
}
893891

894892
static void
895-
modsec_pcre_free(void *ptr)
893+
modsec_pcre_free(const void *ptr)
896894
{
897895
}
898896

@@ -928,7 +926,7 @@ ngx_http_modsecurity_preconfiguration(ngx_conf_t *cf)
928926

929927

930928
static void
931-
ngx_http_modsecurity_terminate(ngx_cycle_t *cycle)
929+
ngx_http_modsecurity_terminate(const ngx_cycle_t *cycle)
932930
{
933931
if (modsec_server) {
934932
modsecTerminate();
@@ -981,7 +979,7 @@ ngx_http_modsecurity_init_process(ngx_cycle_t *cycle)
981979
static ngx_int_t
982980
ngx_http_modsecurity_handler(ngx_http_request_t *r)
983981
{
984-
ngx_http_modsecurity_loc_conf_t *cf;
982+
const ngx_http_modsecurity_loc_conf_t *cf;
985983
ngx_http_modsecurity_ctx_t *ctx;
986984
ngx_int_t rc;
987985

@@ -1089,11 +1087,9 @@ ngx_http_modsecurity_body_handler(ngx_http_request_t *r)
10891087

10901088
static ngx_int_t
10911089
ngx_http_modsecurity_header_filter(ngx_http_request_t *r) {
1092-
ngx_http_modsecurity_loc_conf_t *cf;
1090+
const ngx_http_modsecurity_loc_conf_t *cf;
10931091
ngx_http_modsecurity_ctx_t *ctx;
1094-
const char *location;
1095-
ngx_table_elt_t *h;
1096-
1092+
10971093
cf = ngx_http_get_module_loc_conf(r, ngx_http_modsecurity);
10981094
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity);
10991095

@@ -1103,13 +1099,13 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r) {
11031099
&& r->err_status < 308) {
11041100

11051101
/* 3XX load redirect location header so that we can do redirect in phase 3,4 */
1106-
location = apr_table_get(ctx->req->headers_out, "Location");
1102+
const char *location = apr_table_get(ctx->req->headers_out, "Location");
11071103

11081104
if (location == NULL) {
11091105
return NGX_HTTP_INTERNAL_SERVER_ERROR;
11101106
}
11111107

1112-
h = ngx_list_push(&r->headers_out.headers);
1108+
ngx_table_elt_t *h = ngx_list_push(&r->headers_out.headers);
11131109
if (h == NULL) {
11141110
return NGX_HTTP_INTERNAL_SERVER_ERROR;
11151111
}
@@ -1137,12 +1133,12 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r) {
11371133
static ngx_int_t
11381134
ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
11391135
{
1140-
ngx_http_modsecurity_loc_conf_t *cf;
1141-
ngx_http_modsecurity_ctx_t *ctx;
1142-
ngx_int_t rc;
1143-
apr_off_t content_length;
1144-
ngx_chain_t *cl, *out;
1145-
ngx_int_t last_buf = 0;
1136+
const ngx_http_modsecurity_loc_conf_t *cf;
1137+
ngx_http_modsecurity_ctx_t *ctx;
1138+
ngx_int_t rc;
1139+
apr_off_t content_length;
1140+
ngx_chain_t *cl, *out;
1141+
ngx_int_t last_buf = 0;
11461142

11471143
cf = ngx_http_get_module_loc_conf(r, ngx_http_modsecurity);
11481144
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity);

0 commit comments

Comments
 (0)