summaryrefslogtreecommitdiff
path: root/scripts/coccinelle
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-09-11 18:53:16 -0400
committerNick Mathewson <nickm@torproject.org>2019-09-18 13:43:42 -0400
commit387cfccee47394adeba8cbf49c130cc9b332b025 (patch)
tree20f78875f6533bcf382d3fa1fb627347f33202b8 /scripts/coccinelle
parent41261c3b5cd505f5a601c319eb484866903814af (diff)
downloadtor-387cfccee47394adeba8cbf49c130cc9b332b025.tar.gz
tor-387cfccee47394adeba8cbf49c130cc9b332b025.zip
Add a coccinelle script to look for {inc,dec}rements in log_debug
We want to forbid this pattern since, unlike the other log_*() macros, log_debug() conditionally evaluates its arguments only if debug-level logging is enabled. Thus, a call to log_debug("%d", x++); will only increment x if debugging logs are enabled, which is probably not what the programmer intended. One bug caused by this pattern was #30628. This script detects log_debug( ) calls with any of E++, E--, ++E, or --E in their arguments, where E is an arbitrary expression. Closes ticket 30743.
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r--scripts/coccinelle/debugmm.cocci29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/coccinelle/debugmm.cocci b/scripts/coccinelle/debugmm.cocci
new file mode 100644
index 0000000000..dbd308df33
--- /dev/null
+++ b/scripts/coccinelle/debugmm.cocci
@@ -0,0 +1,29 @@
+// Look for use of expressions with side-effects inside of debug logs.
+//
+// This script detects expressions like ++E, --E, E++, and E-- inside of
+// calls to log_debug().
+//
+// The log_debug() macro exits early if debug logging is not enabled,
+// potentially causing problems if its arguments have side-effects.
+
+@@
+expression E;
+@@
+*log_debug(... , <+... --E ...+>, ... );
+
+
+@@
+expression E;
+@@
+*log_debug(... , <+... ++E ...+>, ... );
+
+@@
+expression E;
+@@
+*log_debug(... , <+... E-- ...+>, ... );
+
+
+@@
+expression E;
+@@
+*log_debug(... , <+... E++ ...+>, ... );