From e27dd590c03a9b4875d58d65e6ba7bb2e080e06d Mon Sep 17 00:00:00 2001 From: songliang Date: Tue, 10 Sep 2024 15:51:52 +0800 Subject: [PATCH] Modify "my_strncat" function The meaning of the "len" parameter in the my_strncat function is the size limit for copying characters from "from", not the size limit for "to" after copying. Also, the "#define safestrcat(to, from) my_strncat(to, from, sizeof(to) - strlen(to) - 1)" has already imposed a limit on max based on the size of "to". Modify the function to prevent truncation of content when too many bytes are passed to the my_strcat function. Signed-off-by: songliang --- 0001-modify-my_strncat-function.patch | 15 +++++++++++++++ sysfsutils.spec | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 0001-modify-my_strncat-function.patch diff --git a/0001-modify-my_strncat-function.patch b/0001-modify-my_strncat-function.patch new file mode 100644 index 0000000..4bfd5db --- /dev/null +++ b/0001-modify-my_strncat-function.patch @@ -0,0 +1,15 @@ +diff --git a/lib/sysfs_utils.c b/lib/sysfs_utils.c +index 46e0849..c0176d1 100644 +--- a/lib/sysfs_utils.c ++++ b/lib/sysfs_utils.c +@@ -375,8 +375,8 @@ char *my_strncat(char *to, const char *from, size_t max) + { + size_t i = 0; + +- while (i < max && to[i] != '\0') ++ while (to[i] != '\0') + i++; +- my_strncpy(to+i, from, max-i); ++ my_strncpy(to+i, from, max); + return to; + } diff --git a/sysfsutils.spec b/sysfsutils.spec index 2c3f91f..883054a 100644 --- a/sysfsutils.spec +++ b/sysfsutils.spec @@ -13,6 +13,8 @@ License: GPLv2 Source0: https://github.com/linux-ras/sysfsutils/archive/v%{version}.tar.gz +Patch1: 0001-modify-my_strncat-function.patch + BuildRequires: autoconf BuildRequires: automake BuildRequires: libtool @@ -89,6 +91,15 @@ find %{buildroot} -type f -name "*.la" -delete %changelog +* Tue Sep 10 2024 songliang - 2.1.1-5 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC: + The meaning of the "len" parameter in the my_strncat function is the size limit for copying characters from "from", not the size limit for "to" after copying. + Also, the "#define safestrcat(to, from) my_strncat(to, from, sizeof(to) - strlen(to) - 1)" has already imposed a limit on max based on the size of "to". + Modify the function to prevent truncation of content when too many bytes are passed to the my_strcat function. + * Mon Mar 20 2023 Guyu Wang - 2.1.1-4 - Rename man file from systool.1.gz to systool.1.zst -- Gitee