[v5,02/52] devtools: forbid use of strerror

Message ID 20241104111037.3632161-3-huangdengdui@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

huangdengdui Nov. 4, 2024, 11:09 a.m. UTC
The function strerror() is insecure in a multi-thread environment.
rte_strerror() or strerror_r() has been provided in DPDK to replace it.
In addition, replace strerror_s with strerror_r on the Windows platform.

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 devtools/checkpatches.sh              | 8 ++++++++
 lib/eal/windows/include/rte_os_shim.h | 1 +
 2 files changed, 9 insertions(+)
  

Patch

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index 4a8591be22..c9ee3550c1 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -210,6 +210,14 @@  check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
+	# refrain from using strerror() for drivers and libs
+	awk -v FOLDERS="lib drivers" \
+		-v EXPRESSIONS="\\\sstrerror\\\(" \
+		-v RET_ON_FAIL=1 \
+		-v MESSAGE='Using strerror, prefer rte_strerror or strerror_r' \
+		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
+		"$1" || res=1
+
 	# refrain from using RTE_LOG_REGISTER for drivers and libs
 	awk -v FOLDERS='lib drivers' \
 		-v EXPRESSIONS='\\<RTE_LOG_REGISTER\\>' \
diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index eda8113662..2bac31e716 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -20,6 +20,7 @@ 
 
 #define strdup(str) _strdup(str)
 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
 #ifndef RTE_TOOLCHAIN_GCC
 #define strcasecmp(s1, s2) _stricmp(s1, s2)
 #define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)