Skip to content

Commit 630dfbd

Browse files
authored
Merge pull request #3488 from umprayz/v2/cppcheck-initial
fix: cppcheck warnings in standalone/
2 parents 50620aa + 1491ab1 commit 630dfbd

File tree

12 files changed

+213
-120
lines changed

12 files changed

+213
-120
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,41 @@ jobs:
137137
run: sudo make install
138138
- name: run regression tests
139139
run: make test-regression
140+
141+
cppcheck:
142+
runs-on: [ubuntu-24.04]
143+
container:
144+
image: debian:sid
145+
steps:
146+
- name: Setup Dependencies
147+
run: |
148+
apt-get update -y -qq
149+
apt-get install -y --no-install-recommends build-essential \
150+
autoconf \
151+
automake \
152+
libtool \
153+
pkg-config \
154+
cppcheck \
155+
apache2-dev \
156+
libpcre2-dev \
157+
libapr1-dev \
158+
libaprutil1-dev \
159+
libxml2-dev \
160+
liblua5.3-dev \
161+
libyajl-dev \
162+
libfuzzy-dev \
163+
ssdeep \
164+
curl \
165+
ca-certificates
166+
- uses: actions/checkout@v4
167+
with:
168+
submodules: false
169+
fetch-depth: 0
170+
- name: configure
171+
run: |
172+
./autogen.sh
173+
./configure --with-apxs=/usr/bin/apxs
174+
- name: cppcheck
175+
run: |
176+
make check-static
177+

Makefile.am

100644100755
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,27 @@ test-regression-nginx:
4040

4141

4242
cppcheck:
43-
cppcheck . --enable=all --force 2>&1 | sed 's/^/warning: /g' 1>&2;
43+
@cppcheck \
44+
-j `getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu || echo 1` \
45+
--enable=all \
46+
--force \
47+
--verbose \
48+
--library=gnu \
49+
--library=posix \
50+
--std=c++17 \
51+
-I ./apache2 \
52+
-I /usr/include/libxml2 \
53+
-I @APXS_INCLUDEDIR@ \
54+
-I @APR_INCLUDEDIR@ \
55+
-I @APU_INCLUDEDIR@ \
56+
--suppressions-list=./tests/cppcheck_suppressions.txt \
57+
--inline-suppr \
58+
--inconclusive \
59+
--template="warning: {file},{line},{severity},{id},{message}" \
60+
--error-exitcode=1 \
61+
standalone/
62+
63+
check-static: cppcheck
4464

4565
check-coding-style:
4666
for i in `(find . -iname "*.c" ; find . -iname "*.h")`; \

autogen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rm -rf autom4te.cache
99
rm -f aclocal.m4
1010
case `uname` in Darwin*) glibtoolize --force --copy ;;
1111
*) libtoolize --force --copy ;; esac
12-
autoreconf --install
12+
autoreconf --install --force
1313
autoheader
1414
automake --add-missing --foreign --copy --force-missing
1515
autoconf --force

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

0 commit comments

Comments
 (0)