lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210904231020.331185-3-yury.norov@gmail.com>
Date:   Sat,  4 Sep 2021 16:10:20 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     Petr Mladek <pmladek@...e.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andy Shevchenko <andy.shevchenko@...il.com>,
        Bartosz Golaszewski <bgolaszewski@...libre.com>,
        Chris Down <chris@...isdown.name>,
        Gilles Muller <Gilles.Muller@...ia.fr>,
        Ingo Molnar <mingo@...nel.org>,
        Jacob Keller <jacob.e.keller@...el.com>,
        Joe Perches <joe@...ches.com>,
        Julia Lawall <Julia.Lawall@...ia.fr>,
        Michal Marek <michal.lkml@...kovi.net>,
        Nicolas Palix <nicolas.palix@...g.fr>,
        Peter Zijlstra <peterz@...radead.org>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Stephen Boyd <swboyd@...omium.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel@...r.kernel.org, cocci@...teme.lip6.fr
Cc:     Yury Norov <yury.norov@...il.com>
Subject: [PATCH 2/2] coccinelle: add script for sputchar()

This script find 47 candidates for sputchar() replacement, 
none of them is false-positive.

Suggested-by: Andy Shevchenko <andy.shevchenko@...il.com>
Signed-off-by: Yury Norov <yury.norov@...il.com>
---
One test case is commented-out because it causes spatch crash.
Coccinelle is installed from ubuntu deb package. 

yury:linux$ spatch --version
spatch version 1.0.8 compiled with OCaml version 4.11.1
Flags passed to the configure script: --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --enable-ocaml --enable-python --enable-opt
OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expressions: PCRE

 scripts/coccinelle/misc/sputchar.cocci | 190 +++++++++++++++++++++++++
 1 file changed, 190 insertions(+)
 create mode 100644 scripts/coccinelle/misc/sputchar.cocci

diff --git a/scripts/coccinelle/misc/sputchar.cocci b/scripts/coccinelle/misc/sputchar.cocci
new file mode 100644
index 000000000000..23fb7546252f
--- /dev/null
+++ b/scripts/coccinelle/misc/sputchar.cocci
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0-only
+///
+/// Check for opencoded sputchar() implementation.
+///
+// Confidence: High
+// Copyright: (C) 2021 Yury Norov
+// Options: --no-includes --include-headers
+//
+// Keywords: sputchar
+//
+
+virtual patch
+virtual org
+virtual report
+virtual context
+
+@...stfix depends on !patch@
+identifier func;
+expression buf, end, c;
+position p;
+@@
+
+func(...)
+{
+	<...
+*	if ((buf) < (end)) {
+*		*(buf) = (c);
+*	}
+*	(buf)++;@p
+	...>
+}
+
+@...efix depends on !patch@
+identifier func;
+expression buf, end, c;
+position p;
+@@
+
+func(...)
+{
+	<...
+*	if ((buf) < (end))
+*		*(buf) = (c);
+*	++(buf);@p
+	...>
+}
+
+@...c1 depends on !patch@
+identifier func;
+expression buf, end, c;
+position p;
+@@
+
+func(...)
+{
+	<...
+*	if ((buf) < (end)) {
+*		*(buf) = (c);
+*	}
+*	(buf) += 1;@p
+	...>
+}
+
+@...c2 depends on !patch@
+identifier func;
+expression buf, end, c;
+position p;
+@@
+
+func(...)
+{
+	<...
+*	if ((buf) < (end)) {
+*		*(buf) = (c);
+*	}
+*	(buf) = (buf) + 1;@p
+	...>
+}
+
+@...stfix depends on patch@
+identifier func;
+expression buf, end, c;
+position p;
+@@
+
+func(...)
+{
+	<...
+-	if ((buf) < (end)) {
+-		*(buf) = (c);
+-	}
+-	(buf)++;@p
++	buf = sputchar(buf, end, c);
+	...>
+}
+
+// @pprefix depends on patch@
+// identifier func;
+// expression buf, end, c;
+// position p;
+// @@
+//
+// func(...)
+// {
+// 	<...
+// -	if ((buf) < (end)) {
+// -		*(buf) = (c);
+// -	}
+// -	++(buf);
+// +	buf = sputchar(buf, end, c);
+// 	...>
+// }
+
+@...c1 depends on patch@
+identifier func;
+expression buf, end, c;
+position p;
+@@
+
+func(...)
+{
+	<...
+-	if ((buf) < (end)) {
+-		*(buf) = (c);
+-	}
+-	(buf) += 1;
++	buf = sputchar(buf, end, c);
+	...>
+}
+
+@...c2 depends on patch@
+identifier func;
+expression buf, end, c;
+position p;
+@@
+
+func(...)
+{
+	<...
+-	if ((buf) < (end)) {
+-		*(buf) = (c);
+-	}
+-	(buf) = (buf) + 1;
++	buf = sputchar(buf, end, c);
+	...>
+}
+
+@...ipt:python depends on report@
+p << rpostfix.p;
+@@
+
+for p0 in p:
+	coccilib.report.print_report(p0, "WARNING opportunity for sputchar()")
+
+@...ipt:python depends on org@
+p << rpostfix.p;
+@@
+
+for p0 in p:
+	coccilib.report.print_report(p0, "WARNING opportunity for sputchar()")
+
+
+@...ipt:python depends on report@
+p << rprefix.p;
+@@
+
+for p0 in p:
+	coccilib.report.print_report(p0, "WARNING opportunity for sputchar()")
+
+@...ipt:python depends on org@
+p << rprefix.p;
+@@
+
+for p0 in p:
+	coccilib.report.print_report(p0, "WARNING opportunity for sputchar()")
+
+@...ipt:python depends on report@
+p << rinc1.p;
+@@
+
+for p0 in p:
+	coccilib.report.print_report(p0, "WARNING opportunity for sputchar()")
+
+@...ipt:python depends on org@
+p << rinc1.p;
+@@
+
+for p0 in p:
+	coccilib.report.print_report(p0, "WARNING opportunity for sputchar()")
+
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ