0001-Modify-my_strncat-function.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. From a13fc5a57ea7c6b1761bc204cb79d8ce4745f57a Mon Sep 17 00:00:00 2001
  2. From: songliang <YS.songliang@h3c.com>
  3. Date: Wed, 4 Jun 2025 15:58:53 +0800
  4. Subject: [PATCH] Modify "my_strncat" function
  5. 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.
  6. 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".
  7. Modify the function to prevent truncation of content when too many bytes are passed to the my_strcat function.
  8. Upstream-Status: Submitted [https://github.com/linux-ras/sysfsutils/pull/30/commits/c2326946c0c2a4206c9b079a9fe25f7f9115295c]
  9. Signed-off-by: songliang <YS.songliang@h3c.com>
  10. Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
  11. ---
  12. lib/sysfs_utils.c | 4 ++--
  13. 1 file changed, 2 insertions(+), 2 deletions(-)
  14. diff --git a/lib/sysfs_utils.c b/lib/sysfs_utils.c
  15. index 46e0849..c0176d1 100644
  16. --- a/lib/sysfs_utils.c
  17. +++ b/lib/sysfs_utils.c
  18. @@ -375,8 +375,8 @@ char *my_strncat(char *to, const char *from, size_t max)
  19. {
  20. size_t i = 0;
  21. - while (i < max && to[i] != '\0')
  22. + while (to[i] != '\0')
  23. i++;
  24. - my_strncpy(to+i, from, max-i);
  25. + my_strncpy(to+i, from, max);
  26. return to;
  27. }
  28. --
  29. 2.34.1