commit e77ad795c68f28e8431dc5b098fba05fcec49c19
parent 99f75373def3520fac4f00c072748f2a0886c923
Author: George Kadianakis <desnacked@riseup.net>
Date: Wed, 25 Sep 2019 14:13:44 +0300
Merge branch 'tor-github/pr/1322'
Diffstat:
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/changes/ticket30743 b/changes/ticket30743
@@ -0,0 +1,7 @@
+ o Minor features (maintenance scripts):
+ - Add a coccinelle script to detect bugs caused by incrementing or
+ decrementing a variable inside a call to log_debug(). Since
+ log_debug() is a macro whose arguments are conditionally evaluated, it
+ is usually an error to do this. One such bug was 30628, in which SENDME
+ cells were miscounted by a decrement operator inside a log_debug()
+ call. Closes ticket 30743.
diff --git a/scripts/coccinelle/debugmm.cocci 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++ ...+>, ... );