[v2,22/22] devtools: check for some reentrant function

Message ID 20231114084133.3573959-23-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series replace strtok with reentrant version |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation fail ninja build failure
ci/github-robot: build fail github build: failed
ci/Intel-compilation fail Compilation issues

Commit Message

Jie Hai Nov. 14, 2023, 8:41 a.m. UTC
  Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

This patch adds check in checkpatches.sh for strtok, which is
non-reentrant.

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Patch

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index 066449d147e8..0a936219c069 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -119,6 +119,14 @@  check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
+	# refrain from using some non-reentrant functions
+	awk -v FOLDERS="lib drivers app examples" \
+		-v EXPRESSIONS="strtok\\\(" \
+		-v RET_ON_FAIL=1 \
+		-v MESSAGE='Using non-reentrant function strtok, prefer strtok_s' \
+		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
+		"$1" || res=1
+
 	# refrain from using some pthread functions
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \