From 8a1d5f5f41aa8669c33ee9640cdf944169b9e891 Mon Sep 17 00:00:00 2001 From: songliang Date: Tue, 10 Sep 2024 11:14:53 +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 --- 0004-modify-my_strncat-function.patch | 15 +++++++++++++++ sysfsutils.spec | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 0004-modify-my_strncat-function.patch diff --git a/0004-modify-my_strncat-function.patch b/0004-modify-my_strncat-function.patch new file mode 100644 index 0000000..4bfd5db --- /dev/null +++ b/0004-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 a02f4b0..a9138d2 100644 --- a/sysfsutils.spec +++ b/sysfsutils.spec @@ -1,6 +1,6 @@ Name: sysfsutils Version: 2.1.1 -Release: 4 +Release: 5 Summary: A set of utilities for interfacing with sysfs License: GPL-2.0-only URL: https://github.com/linux-ras/sysfsutils @@ -10,6 +10,7 @@ Source0: https://github.com/linux-ras/sysfsutils/archive/v%{version}.tar.gz Patch1: 0001-lib-Fixed-a-memory-leak-in-lib-sysfs_driver.patch Patch2: 0002-lib-Fixed-memory-leaks-in-lib-sysfs_device.c.patch Patch3: 0003-lib-Fixed-memory-leaks-in-lib-sysfs_attr.c.patch +Patch4: 0004-modify-my_strncat-function.patch BuildRequires: gcc chrpath autoconf automake make libtool Provides: libsysfs libsysfs%{?_isa} @@ -83,6 +84,15 @@ chrpath -d $(find $RPM_BUILD_ROOT -name systool) %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. + * Tue Jul 30 2024 zhangjian - 2.1.1-4 - Type:bugfix - ID:NA -- Gitee