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(+)
@@ -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\\>' \
@@ -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)