[PATCH] coccinelle: Add rules to find str_down_up() replacements
From: Kees Cook
Date: Mon Aug 12 2024 - 14:36:45 EST
As done with str_up_down(), add checks for str_down_up() opportunities.
5 cases currently exist in the tree.
Suggested-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
Signed-off-by: Kees Cook <kees@xxxxxxxxxx>
---
Cc: Andy Shevchenko <andy@xxxxxxxxxx>
Cc: Michal Wajdeczko <michal.wajdeczko@xxxxxxxxx>
Cc: Julia Lawall <Julia.Lawall@xxxxxxxx>
Cc: Nicolas Palix <nicolas.palix@xxxxxxx>
Cc: linux-hardening@xxxxxxxxxxxxxxx
Cc: cocci@xxxxxxxx
---
scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
index d517f6bc850b..5e729f187f22 100644
--- a/scripts/coccinelle/api/string_choices.cocci
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -62,3 +62,26 @@ e << str_up_down_r.E;
@@
coccilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)
+
+@str_down_up depends on patch@
+expression E;
+@@
+(
+- ((E) ? "down" : "up")
++ str_down_up(E)
+)
+
+@str_down_up_r depends on !patch exists@
+expression E;
+position P;
+@@
+(
+* ((E@P) ? "down" : "up")
+)
+
+@script:python depends on report@
+p << str_down_up_r.P;
+e << str_down_up_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)
--
2.34.1