From 4564a465ab055059e3e0d10b1c1e95e6d890ad1e Mon Sep 17 00:00:00 2001 From: songliang Date: Mon, 9 Sep 2024 16:16:37 +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 | 1 + 2 files changed, 16 insertions(+) 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..9634544 100644 --- a/sysfsutils.spec +++ b/sysfsutils.spec @@ -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} -- Gitee