From: "cron2 (Code Review)" Date: Wed, 22 Apr 2026 07:46:27 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="jLZJh47PEWk="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: dev-tools: Add script to run cppcheck against the code-base List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --jLZJh47PEWk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#6) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1620?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: dev-tools: Add script to run cppcheck against the code-base ...................................................................... dev-tools: Add script to run cppcheck against the code-base Also add a suitable suppressions-list file to make it possible to run it without reporting errors. Tested with cppcheck 2.19.0 (Ubuntu 26.04). Change-Id: I125cf63f11257d7245ead2f7feafb86b841580a5 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1620 Message-Id: <20260419134205.21459-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 664.html Signed-off-by: Gert Doering --- M Makefile.am A dev-tools/cppcheck-suppression A dev-tools/run-cppcheck.sh 3 files changed, 120 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/20/1620/6 diff --git a/Makefile.am b/Makefile.am index 362ae96..2df7eea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,3 +89,10 @@ doxygen: $(MAKE) -C doc/doxygen doxygen + +.PHONY: cppcheck +cppcheck: + BUILD_DIR=3D"$(abs_top_builddir)" \ + SOURCE_DIR=3D"$(abs_top_srcdir)" \ + INCLUDE_FLAGS=3D"$(LIBNL_GENL_CFLAGS)" \ + "$(top_srcdir)/dev-tools/run-cppcheck.sh" diff --git a/dev-tools/cppcheck-suppression b/dev-tools/cppcheck-suppression new file mode 100644 index 0000000..1f31edb --- /dev/null +++ b/dev-tools/cppcheck-suppression @@ -0,0 +1,87 @@ +# We start with --enable=3Dall, but then suppress some issues that have to= o many +# occurences right now. They still should be fixed at some point +constParameter +constParameterCallback +constParameterPointer +constVariable +constVariablePointer +variableScope +# We have a lot of library includes, not all of them are really required, +# so ignore them +missingIncludeSystem +# cppcheck doesn't understand about check_malloc_return, so these are +# usually misleading +nullPointerOutOfMemory +nullPointerArithmeticOutOfMemory +# These are specific false-positives (FP) or ignored (IGN) issues +# We might want to move some of them to inline-suppression to avoid +# the static line-numbers +# IGN: multi code does weird things with pointers to local variables... +autoVariables:src/openvpn/multi.c:4177 +autoVariables:src/openvpn/multi_io.c:280 +# IGN: the code header =3D 0 | (OPCODE << P_OPCODE_SHIFT) is used intentio= nally +badBitmaskCheck:src/openvpn/mudp.c +badBitmaskCheck:tests/unit_tests/openvpn/test_pkt.c +# IGN: event code uses a pointer to store integers +intToPointerCast:src/openvpn/multi_io.c +intToPointerCast:src/openvpn/forward.c +# FP: crt_error is always true on Unix, but not Windows +knownConditionTrueFalse:src/openvpn/error.h:380 +# FP: code needs to accomodate many different defines +knownConditionTrueFalse:src/openvpn/event.c:1148 +# FP: dco_win support has "false" stubs +knownConditionTrueFalse:src/openvpn/forward.c +knownConditionTrueFalse:src/openvpn/init.c +knownConditionTrueFalse:src/openvpn/multi_io.c:163 +# FP: cppcheck thinks that management_query_user_pass is always true, +# but no idea why +knownConditionTrueFalse:src/openvpn/misc.c:97 +# FP: cert_uri_supported is a wrapper around defines, so it's +# always constant but differs depending on OpenSSL version +knownConditionTrueFalse:src/openvpn/ssl_openssl.c:1258 +# FP: cppcheck doesn't understand that the function changes szErrMessage +knownConditionTrueFalse:src/tapctl/main.c:704 +knownConditionTrueFalse:src/openvpnmsica/dllmain.c:164 +# FP: cppcheck seems to be confused since we cast the pointer to integer +memleak:src/plugins/down-root/down-root.c:337 +# FP: eventmsg.h is not built on Unix +missingInclude:src/openvpnserv/common.c:25 +# IGN: strlen(NULL) is not nice code, but seems to work +nullPointerRedundantCheck:src/openvpn/init.c:299 +# IGN: We reuse the same variable name due to macro usage +shadowVariable:src/openvpn/options.c:2580 +shadowVariable:src/openvpn/options.c:2598 +# FP: yes, t_prev is unitialized, but t_prev_len is 0, so that's handled +uninitvar:src/openvpn/crypto_epoch.c:60 +# FP: yes, parm is unitialized, but parm_len is 0, so that's handled +uninitvar:src/openvpn/options_parse.c:148 +# FP: uninit is fine when it is a return parameter +ctuuninitvar:src/openvpn/crypto_mbedtls_legacy.c:698 +uninitvar:src/openvpnserv/interactive.c:1935 +uninitvar:src/tapctl/main.c:566 +# FP: cppcheck doesn't account for short-circuiting +unreadVariable:src/openvpn/manage.c:682 +unusedFunction:src/openvpn/siphash_reference.c +# FP: exported as DLL +unusedFunction:src/openvpnmsica/*.c +# FP: loaded as plugins +unusedFunction:src/plugins/* +unusedFunction:sample/sample-plugins/* +# FP: wmain +unusedFunction:src/tapctl/main.c:613 +unusedFunction:tests/unit_tests/openvpnserv/test_openvpnserv.c +# IGN: keep mocking around for future use +unusedFunction:tests/unit_tests/openvpn/mock_msg.c +# FP: doesn't account for --wrap +unusedFunction:tests/unit_tests/openvpn/test_tls_crypt.c +unusedFunction:/usr/include/* +# IGN: old code that is difficult to test (MSG_ERRQUEUE), ignore for now +unusedStructMember:src/openvpn/mtu.c:281 +# FP: used implictly by NL macros +unusedStructMember:src/openvpn/networking_sitnl.c +# IGN: keep explanatory fields in test data +unusedStructMember:tests/unit_tests/openvpn/test_pkcs11.c +# IGN: nicer to assign generic "arg" early +variableScope:src/openvpn/networking_sitnl.c:1390 +# IGN: nicer to keep the "variable" earlier +variableScope:src/openvpnserv/interactive.c:2687 diff --git a/dev-tools/run-cppcheck.sh b/dev-tools/run-cppcheck.sh new file mode 100755 index 0000000..674fc092 --- /dev/null +++ b/dev-tools/run-cppcheck.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -eu + +SCRIPT_DIR=3D$(dirname $(readlink -e "${BASH_SOURCE[0]}")) +: ${SOURCE_DIR:=3D$SCRIPT_DIR/..} +: ${BUILD_DIR:=3D$PWD} +: ${INCLUDE_FLAGS:=3D} +CPPCHECK_DIR=3D"${BUILD_DIR}/cppcheck_build_dir" + +set -x + +mkdir -p "$CPPCHECK_DIR" +cd "${SOURCE_DIR}" +cppcheck -j$(nproc) \ + -DHAVE_CONFIG_H -U_WIN32 \ + -DMBEDTLS_SSL_PROTO_TLS1_3 -DMBEDTLS_SSL_KEYING_MATERIAL_EXPORT \ + -I./include/ -I./tests/unit_tests/openvpn/ \ + -I./src/compat/ -I./src/openvpn/ -I./src/openvpnserv/ -I./src/plugins/au= th-pam/ \ + -I"${BUILD_DIR}" -I"${BUILD_DIR}/include/" $INCLUDE_FLAGS \ + --enable=3Dall \ + --suppressions-list=3D"${SCRIPT_DIR}/cppcheck-suppression" \ + --cppcheck-build-dir=3D"${CPPCHECK_DIR}" \ + --check-level=3Dexhaustive \ + --error-exitcode=3D1 \ + src/ tests/ sample/ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1620?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I125cf63f11257d7245ead2f7feafb86b841580a5 Gerrit-Change-Number: 1620 Gerrit-PatchSet: 6 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --jLZJh47PEWk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #6 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

dev-tools: Add script to run cppche=
ck against the code-base

Also add a suitable suppressions-list file = to
make it possible to run it without reporting
errors.

Tested= with cppcheck 2.19.0 (Ubuntu 26.04).

Change-Id: I125cf63f11257d7245= ead2f7feafb86b841580a5
Signed-off-by: Frank Lichtenheld <frank@...2716...= 1...>
Acked-by: Gert Doering <gert@...1296...>
Gerrit URL: h= ttps://gerrit.openvpn.net/c/openvpn/+/1620
Message-Id: <2026041913420= 5.21459-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-= devel@lists.sourceforge.net/msg36664.html
Signed-off-by: Gert Doering &l= t;gert@...1296...>
---
M Makefile.am
A dev-tools/cppcheck-suppr= ession
A dev-tools/run-cppcheck.sh
3 files changed, 120 insertions(+)= , 0 deletions(-)

git pull ssh://gerrit.openvpn.n=
et:29418/openvpn refs/changes/20/1620/6
diff --git a/Makefile.am b/=
Makefile.am
index 362ae96..2df7eea 100644
-= -- a/Makefile.am
+++ b/Makefile.am
@@ -89,3= +89,10 @@

doxygen:
$(= MAKE) -C doc/doxygen doxygen
+
+.PHONY: cp= pcheck
+cppcheck:
+ BUILD_DIR=3D"$(ab= s_top_builddir)" \
+ SOURCE_DIR=3D"$(abs_top_srcdir)" \
+ INCLUDE_FLAGS=3D"$(LIBNL_GENL_CFLAGS)&q= uot; \
+ "$(top= _srcdir)/dev-tools/run-cppcheck.sh"
diff --git a/dev-t= ools/cppcheck-suppression b/dev-tools/cppcheck-suppression
= new file mode 100644
index 0000000..1f31edb
--- /dev/null

+++ b/dev-tools/cppcheck-suppression<= br>@@ -0,0 +1,87 @@
+# We start with --enable=3Dall, but then suppress some issues that ha= ve too many
+# occure= nces right now. They still should be fixed at some point
+constParameter
+constParameterCallback
+constParameterPointer
+constVariable
+constVariablePointer
+variableScope
+# We have a lot of library includes, not all o= f them are really required,
+# so ignore them
+missingIncludeSystem
+# cppcheck doesn't understand about check_malloc_return, so these= are
+# usually misle= ading
+nullPointerOut= OfMemory
+nullPointer= ArithmeticOutOfMemory
+# These are specific false-positives (FP) or ignored (IGN) issues<= br>+# We might want to move som= e of them to inline-suppression to avoid
+# the static line-numbers
+# IGN: multi code does weird things with pointer= s to local variables...
+autoVariables:src/openvpn/multi.c:4177
+autoVariables:src/openvpn/multi_io.c:280
<= span style=3D"color: hsl(120, 100%, 40%);">+# IGN: the code header =3D 0 | = (OPCODE << P_OPCODE_SHIFT) is used intentionally
+badBitmaskCheck:src/openvpn/mudp.c
+badBitmaskCheck:tests/uni= t_tests/openvpn/test_pkt.c
+# IGN: event code uses a pointer to store integers
+intToPointerCast:src/openvpn/multi_io= .c
+intToPointerCast:= src/openvpn/forward.c
+# FP: crt_error is always true on Unix, but not Windows
+knownConditionTrueFalse:src/openvpn/e= rror.h:380
+# FP: cod= e needs to accomodate many different defines
+knownConditionTrueFalse:src/openvpn/event.c:1148
+# FP: dco_win support= has "false" stubs
+knownConditionTrueFalse:src/openvpn/forward.c
+knownConditionTrueFalse:src/openvpn/init= .c
+knownConditionTru= eFalse:src/openvpn/multi_io.c:163
+# FP: cppcheck thinks that management_query_user_pass is alwa= ys true,
+# but no id= ea why
+knownConditio= nTrueFalse:src/openvpn/misc.c:97
+# FP: cert_uri_supported is a wrapper around defines, so it= 9;s
+# always constan= t but differs depending on OpenSSL version
+knownConditionTrueFalse:src/openvpn/ssl_openssl.c:12= 58
+# FP: cppcheck do= esn't understand that the function changes szErrMessage
+knownConditionTrueFalse:src/tapctl/= main.c:704

+knownCond= itionTrueFalse:src/openvpnmsica/dllmain.c:164
+# FP: cppcheck seems to be confused since we cast= the pointer to integer
+memleak:src/plugins/down-root/down-root.c:337
+# FP: eventmsg.h is not built on Unix<= br>+missingInclude:src/openvpns= erv/common.c:25
+# IG= N: strlen(NULL) is not nice code, but seems to work
+nullPointerRedundantCheck:src/openvpn/ini= t.c:299
+# IGN: We re= use the same variable name due to macro usage
+shadowVariable:src/openvpn/options.c:2580<= br>+shadowVariable:src/openvpn/= options.c:2598
+# FP:= yes, t_prev is unitialized, but t_prev_len is 0, so that's handled
+uninitvar:src/openvpn/c= rypto_epoch.c:60
+# F= P: yes, parm is unitialized, but parm_len is 0, so that's handled
+uninitvar:src/openvpn/opt= ions_parse.c:148
+# F= P: uninit is fine when it is a return parameter
+ctuuninitvar:src/openvpn/crypto_mbedtls_legacy.= c:698
+uninitvar:src/= openvpnserv/interactive.c:1935
+uninitvar:src/tapctl/main.c:566
+# FP: cppcheck doesn't account for short-circuit= ing
+unreadVariable:s= rc/openvpn/manage.c:682
+unusedFunction:src/openvpn/siphash_reference.c
+# FP: exported as DLL
+unusedFunction:src/openvpnmsica/*.c
+# FP: loaded as plugins
+unusedFunction:src/pl= ugins/*
+unusedFuncti= on:sample/sample-plugins/*
+# FP: wmain
+u= nusedFunction:src/tapctl/main.c:613
+unusedFunction:tests/unit_tests/openvpnserv/test_openvpnser= v.c
+# IGN: keep mock= ing around for future use
+unusedFunction:tests/unit_tests/openvpn/mock_msg.c
+# FP: doesn't account for --wrap
+unusedFunction:tests/= unit_tests/openvpn/test_tls_crypt.c
+unusedFunction:/usr/include/*
+# IGN: old code that is difficult to test (MSG_ER= RQUEUE), ignore for now
+unusedStructMember:src/openvpn/mtu.c:281
+# FP: used implictly by NL macros
+unusedStructMember:src/openvpn/netwo= rking_sitnl.c
+# IGN:= keep explanatory fields in test data
+unusedStructMember:tests/unit_tests/openvpn/test_pkcs11.c=
+# IGN: nicer to ass= ign generic "arg" early
+variableScope:src/openvpn/networking_sitnl.c:1390
<= span style=3D"color: hsl(120, 100%, 40%);">+# IGN: nicer to keep the "= variable" earlier

+
+set -eu
+
+SCRIPT_DIR=3D$(dirname $(readlink -e "${BASH_SOURC= E[0]}"))
+: ${SO= URCE_DIR:=3D$SCRIPT_DIR/..}
+: ${BUILD_DIR:=3D$PWD}
+: ${INCLUDE_FLAGS:=3D}
+CPPCHECK_DIR=3D"${BUILD_DIR}/cppcheck_build_dir"
+
+set -x
+
+mkdir -p "$CPPCHECK_DIR"
+cd "${SOURCE_DIR}"
+cppcheck -j$(nproc) \
+ -DHAVE_CONFIG_H -U_WIN32 \
+ -DMBEDTLS_SSL_PROTO_TLS1_3 -D= MBEDTLS_SSL_KEYING_MATERIAL_EXPORT \
+ -I./include/ -I./tests/unit_tests/openvpn/ \
<= span style=3D"color: hsl(120, 100%, 40%);">+ -I./src/compat/ -I./src/openv= pn/ -I./src/openvpnserv/ -I./src/plugins/auth-pam/ \

+ -I"${BUILD_DIR}" -I"${BU= ILD_DIR}/include/" $INCLUDE_FLAGS \
+ --enable=3Dall \
+ --suppressions-list=3D"${SCRIPT_DIR}/cppcheck-su= ppression" \
+ = --cppcheck-build-dir=3D"${CPPCHECK_DIR}" \
+ --check-level=3Dexhaustive \
= + --error-exitcode=3D1 \
+ src/ tests/ sample/

To view, visit change 1620. To unsubscribe, or= for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I125cf63f11257d7245ead2f7fea= fb86b841580a5
Gerrit-Change-Number: 1620
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --jLZJh47PEWk=--