Skip to content

Commit 09e035a

Browse files
committed
fix cppcheck warnings
1 parent 50620aa commit 09e035a

8 files changed

Lines changed: 130 additions & 118 deletions

File tree

standalone/api.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ apr_status_t ap_http_in_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
180180
int is_eos = 0;
181181
apr_bucket_brigade *bb_in;
182182
apr_bucket *after;
183-
apr_status_t rv;
184183

185184
bb_in = modsecGetBodyBrigade(f->r);
186185

@@ -191,7 +190,7 @@ apr_status_t ap_http_in_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
191190
APR_BRIGADE_INSERT_TAIL(bb_in, e);
192191
}
193192

194-
rv = apr_brigade_partition(bb_in, readbytes, &after);
193+
apr_status_t rv = apr_brigade_partition(bb_in, readbytes, &after);
195194
if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) {
196195
return rv;
197196
}
@@ -278,15 +277,15 @@ const char *modsecProcessConfig(directory_config *config, const char *file, cons
278277

279278
if(dir[li] != '/' && dir[li] != '\\')
280279
#ifdef WIN32
281-
file = apr_pstrcat(config->mp, dir, "\\", file, NULL);
280+
file = apr_pstrcat(config->mp, dir, "\\", file, (char *)NULL);
282281
#else
283-
file = apr_pstrcat(config->mp, dir, "/", file, NULL);
282+
file = apr_pstrcat(config->mp, dir, "/", file, (char *)NULL);
284283
#endif
285284
else
286-
file = apr_pstrcat(config->mp, dir, file, NULL);
285+
file = apr_pstrcat(config->mp, dir, file, (char *)NULL);
287286
}
288287
else if (APR_EBADPATH == status) {
289-
return apr_pstrcat(config->mp, "Config file has a bad path, ", file, NULL);
288+
return apr_pstrcat(config->mp, "Config file has a bad path, ", file, (char *)NULL);
290289
}
291290

292291
apr_pool_create(&ptemp, config->mp);
@@ -403,7 +402,7 @@ request_rec *modsecNewRequest(conn_rec *connection, directory_config *config)
403402

404403
static modsec_rec *retrieve_msr(request_rec *r) {
405404
modsec_rec *msr = NULL;
406-
request_rec *rx = NULL;
405+
const request_rec *rx = NULL;
407406

408407
/* Look in the current request first. */
409408
msr = (modsec_rec *)apr_table_get(r->notes, NOTE_MSR);

standalone/api.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void modsecInitProcess();
5858

5959
conn_rec *modsecNewConnection();
6060
void modsecProcessConnection(conn_rec *c);
61-
int modsecFinishConnection(conn_rec *c);
61+
int modsecFinishConnection(conn_rec *c);
6262

6363
request_rec *modsecNewRequest(conn_rec *connection, directory_config *config);
6464

@@ -86,22 +86,40 @@ void modsecSetLogHook(void *obj, void (*hook)(void *obj, int level, char *str));
8686

8787
static inline void
8888
modsecSetBodyBrigade(request_rec *r, apr_bucket_brigade *b) {
89+
#ifdef __cplusplus
90+
apr_table_setn(r->notes, NOTE_MSR_BRIGADE_REQUEST, reinterpret_cast<char *>(b)); //NOSONAR
91+
#else
8992
apr_table_setn(r->notes, NOTE_MSR_BRIGADE_REQUEST, (char *)b);
93+
#endif
9094
};
9195

92-
static inline apr_bucket_brigade *
93-
modsecGetBodyBrigade(request_rec *r) {
96+
static inline apr_bucket_brigade * modsecGetBodyBrigade(const request_rec *r) {
97+
#ifdef __cplusplus
98+
return reinterpret_cast<apr_bucket_brigade *>(
99+
const_cast<char *>(apr_table_get(r->notes, NOTE_MSR_BRIGADE_REQUEST))
100+
);
101+
#else
94102
return (apr_bucket_brigade *)apr_table_get(r->notes, NOTE_MSR_BRIGADE_REQUEST);
103+
#endif
95104
};
96105

97106
static inline void
98107
modsecSetResponseBrigade(request_rec *r, apr_bucket_brigade *b) {
108+
#ifdef __cplusplus
109+
apr_table_setn(r->notes, NOTE_MSR_BRIGADE_RESPONSE, reinterpret_cast<char *>(b)); //NOSONAR
110+
#else
99111
apr_table_setn(r->notes, NOTE_MSR_BRIGADE_RESPONSE, (char *)b);
112+
#endif
100113
};
101114

102-
static inline apr_bucket_brigade *
103-
modsecGetResponseBrigade(request_rec *r) {
115+
static inline apr_bucket_brigade * modsecGetResponseBrigade(const request_rec *r) {
116+
#ifdef __cplusplus
117+
return reinterpret_cast<apr_bucket_brigade *>(
118+
const_cast<char *>(apr_table_get(r->notes, NOTE_MSR_BRIGADE_RESPONSE))
119+
);
120+
#else
104121
return (apr_bucket_brigade *)apr_table_get(r->notes, NOTE_MSR_BRIGADE_RESPONSE);
122+
#endif
105123
};
106124

107125
void modsecSetReadBody(apr_status_t (*func)(request_rec *r, char *buf, unsigned int length, unsigned int *readcnt, int *is_eos));
@@ -121,7 +139,7 @@ const char *modsecIsServerSignatureAvailale(void);
121139

122140
#ifdef VERSION_IIS
123141
void modsecStatusEngineCall(void);
124-
void modsecReportRemoteLoadedRules(void);
142+
void modsecReportRemoteLoadedRules(void);
125143
#endif
126144

127145
#ifdef __cplusplus

standalone/buckets.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ AP_DECLARE(apr_status_t) ap_pass_brigade(ap_filter_t *next,
5757
apr_bucket_brigade *bb)
5858
{
5959
if (next) {
60-
apr_bucket *e;
60+
const apr_bucket *e;
6161
if ((e = APR_BRIGADE_LAST(bb)) && APR_BUCKET_IS_EOS(e) && next->r) {
6262
/* This is only safe because HTTP_HEADER filter is always in
6363
* the filter stack. This ensures that there is ALWAYS a
@@ -89,7 +89,7 @@ AP_DECLARE(apr_status_t) ap_save_brigade(ap_filter_t *f,
8989
apr_bucket_brigade **b, apr_pool_t *p)
9090
{
9191
apr_bucket *e;
92-
apr_status_t rv, srv = APR_SUCCESS;
92+
apr_status_t srv = APR_SUCCESS;
9393

9494
/* If have never stored any data in the filter, then we had better
9595
* create an empty bucket brigade so that we can concat.
@@ -98,11 +98,12 @@ AP_DECLARE(apr_status_t) ap_save_brigade(ap_filter_t *f,
9898
*saveto = apr_brigade_create(p, f->c->bucket_alloc);
9999
}
100100

101-
for (e = APR_BRIGADE_FIRST(*b);
102-
e != APR_BRIGADE_SENTINEL(*b);
101+
const apr_bucket_brigade *bb = *b;
102+
for (e = APR_BRIGADE_FIRST(bb);
103+
e != APR_BRIGADE_SENTINEL(bb);
103104
e = APR_BUCKET_NEXT(e))
104105
{
105-
rv = apr_bucket_setaside(e, p);
106+
apr_status_t rv = apr_bucket_setaside(e, p);
106107

107108
/* If the bucket type does not implement setaside, then
108109
* (hopefully) morph it into a bucket type which does, and set

standalone/config.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
533533
const char *errmsg = NULL;
534534

535535
if ((parms->override & cmd->req_override) == 0)
536-
return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
536+
return apr_pstrcat(parms->pool, cmd->name, " not allowed here", (char *)NULL);
537537

538538
parms->info = cmd->cmd_data;
539539
parms->cmd = cmd;
@@ -565,7 +565,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
565565
case NO_ARGS:
566566
if (*args != 0)
567567
return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
568-
NULL);
568+
(char *)NULL);
569569

570570
return cmd->AP_NO_ARGS(parms, mconfig);
571571

@@ -574,7 +574,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
574574

575575
if (*w == '\0' || *args != 0)
576576
return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
577-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
577+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
578578

579579
return cmd->AP_TAKE1(parms, mconfig, w);
580580

@@ -584,7 +584,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
584584

585585
if (*w == '\0' || *w2 == '\0' || *args != 0)
586586
return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
587-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
587+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
588588

589589
return cmd->AP_TAKE2(parms, mconfig, w, w2);
590590

@@ -594,7 +594,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
594594

595595
if (*w == '\0' || *args != 0)
596596
return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
597-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
597+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
598598

599599
return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
600600

@@ -605,7 +605,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
605605

606606
if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
607607
return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
608-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
608+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
609609

610610
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
611611

@@ -617,7 +617,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
617617
if (*w == '\0' || *w2 == '\0' || *args != 0)
618618
return apr_pstrcat(parms->pool, cmd->name,
619619
" takes two or three arguments",
620-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
620+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
621621

622622
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
623623

@@ -629,7 +629,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
629629
if (*w == '\0' || *args != 0)
630630
return apr_pstrcat(parms->pool, cmd->name,
631631
" takes one, two or three arguments",
632-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
632+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
633633

634634
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
635635

@@ -641,7 +641,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
641641
if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
642642
return apr_pstrcat(parms->pool, cmd->name,
643643
" takes one or three arguments",
644-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
644+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
645645

646646
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
647647

@@ -662,7 +662,7 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
662662
if (*w == '\0' || *args == 0)
663663
return apr_pstrcat(parms->pool, cmd->name,
664664
" requires at least two arguments",
665-
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
665+
cmd->errmsg ? ", " : NULL, cmd->errmsg, (char *)NULL);
666666

667667
while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') {
668668

@@ -679,14 +679,14 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
679679

680680
if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
681681
return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
682-
NULL);
682+
(char *)NULL);
683683

684684
return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
685685

686686
default:
687687
return apr_pstrcat(parms->pool, cmd->name,
688688
" is improperly configured internally (server bug)",
689-
NULL);
689+
(char *)NULL);
690690
}
691691
}
692692

@@ -797,13 +797,9 @@ static const char *process_resource_config_nofnmatch(const char *fname,
797797
unsigned depth,
798798
int optional)
799799
{
800-
const char *error;
801-
apr_status_t rv;
802-
803800
if (ap_is_directory(ptemp, fname)) {
804801
apr_dir_t *dirp;
805802
apr_finfo_t dirent;
806-
int current;
807803
apr_array_header_t *candidates = NULL;
808804
fnames *fnew;
809805
char *path = apr_pstrdup(ptemp, fname);
@@ -820,7 +816,7 @@ static const char *process_resource_config_nofnmatch(const char *fname,
820816
* entries here and store 'em away. Recall we need full pathnames
821817
* for this.
822818
*/
823-
rv = apr_dir_open(&dirp, path, ptemp);
819+
apr_status_t rv = apr_dir_open(&dirp, path, ptemp);
824820
if (rv != APR_SUCCESS) {
825821
char errmsg[120];
826822
return apr_psprintf(p, "Could not open config directory %s: %s",
@@ -846,9 +842,9 @@ static const char *process_resource_config_nofnmatch(const char *fname,
846842
* Now recurse these... we handle errors and subdirectories
847843
* via the recursion, which is nice
848844
*/
849-
for (current = 0; current < candidates->nelts; ++current) {
845+
for (int current = 0; current < candidates->nelts; ++current) {
850846
fnew = &((fnames *) candidates->elts)[current];
851-
error = process_resource_config_nofnmatch(fnew->fname,
847+
const char *error = process_resource_config_nofnmatch(fnew->fname,
852848
ari, p, ptemp,
853849
depth, optional);
854850
if (error) {
@@ -877,7 +873,6 @@ static const char *process_resource_config_fnmatch(const char *path,
877873
apr_finfo_t dirent;
878874
apr_array_header_t *candidates = NULL;
879875
fnames *fnew;
880-
int current;
881876

882877
/* find the first part of the filename */
883878
rest = ap_strchr_c(fname, '/');
@@ -947,7 +942,7 @@ static const char *process_resource_config_fnmatch(const char *path,
947942
* Now recurse these... we handle errors and subdirectories
948943
* via the recursion, which is nice
949944
*/
950-
for (current = 0; current < candidates->nelts; ++current) {
945+
for (int current = 0; current < candidates->nelts; ++current) {
951946
fnew = &((fnames *) candidates->elts)[current];
952947
if (!rest) {
953948
error = process_resource_config_nofnmatch(fnew->fname,
@@ -993,10 +988,10 @@ AP_DECLARE(const char *) process_fnmatch_configs(apr_array_header_t *ari,
993988

994989
/* we allow APR_SUCCESS and APR_EINCOMPLETE */
995990
if (APR_ERELATIVE == status) {
996-
return apr_pstrcat(p, "Include must have an absolute path, ", fname, NULL);
991+
return apr_pstrcat(p, "Include must have an absolute path, ", fname, (char *)NULL);
997992
}
998993
else if (APR_EBADPATH == status) {
999-
return apr_pstrcat(p, "Include has a bad path, ", fname, NULL);
994+
return apr_pstrcat(p, "Include has a bad path, ", fname, (char *)NULL);
1000995
}
1001996

1002997
/* walk the filepath */
@@ -1056,7 +1051,7 @@ const char *process_command_config(server_rec *s,
10561051
if(status != APR_SUCCESS)
10571052
{
10581053
apr_array_pop(arr);
1059-
errmsg = apr_pstrcat(p, "Cannot open config file: ", fn, NULL);
1054+
errmsg = apr_pstrcat(p, "Cannot open config file: ", fn, (char *)NULL);
10601055
goto Exit;
10611056
}
10621057
}
@@ -1098,7 +1093,7 @@ const char *process_command_config(server_rec *s,
10981093
if (*w == '\0' || *args != 0)
10991094
{
11001095
ap_cfg_closefile(parms->config_file);
1101-
errmsg = apr_pstrcat(parms->pool, "Include takes one argument", NULL);
1096+
errmsg = apr_pstrcat(parms->pool, "Include takes one argument", (char *)NULL);
11021097
goto Exit;
11031098
}
11041099

@@ -1115,11 +1110,11 @@ const char *process_command_config(server_rec *s,
11151110
while(li >= 0 && configfilepath[li] != '/' && configfilepath[li] != '\\')
11161111
configfilepath[li--] = 0;
11171112

1118-
w = apr_pstrcat(p, configfilepath, w, NULL);
1113+
w = apr_pstrcat(p, configfilepath, w, (char *)NULL);
11191114
}
11201115
else if (APR_EBADPATH == status) {
11211116
ap_cfg_closefile(parms->config_file);
1122-
errmsg = apr_pstrcat(p, "Include file has a bad path, ", w, NULL);
1117+
errmsg = apr_pstrcat(p, "Include file has a bad path, ", w, (char *)NULL);
11231118
goto Exit;
11241119
}
11251120

@@ -1143,7 +1138,7 @@ const char *process_command_config(server_rec *s,
11431138
// unknown command, should error
11441139
//
11451140
ap_cfg_closefile(parms->config_file);
1146-
errmsg = apr_pstrcat(p, "Unknown command in config: ", cmd_name, NULL);
1141+
errmsg = apr_pstrcat(p, "Unknown command in config: ", cmd_name, (char *)NULL);
11471142
goto Exit;
11481143
}
11491144

standalone/filters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ AP_DECLARE(ap_filter_t *) ap_add_output_filter(const char *name, void *ctx,
210210
r ? &r->proto_output_filters : NULL, &c->output_filters);
211211
}
212212

213-
static void remove_any_filter(ap_filter_t *f, ap_filter_t **r_filt, ap_filter_t **p_filt,
213+
static void remove_any_filter(const ap_filter_t *f, ap_filter_t **r_filt, ap_filter_t **p_filt,
214214
ap_filter_t **c_filt)
215215
{
216216
ap_filter_t **curr = r_filt ? r_filt : c_filt;

0 commit comments

Comments
 (0)