diff --git a/backport-fix-mem-leaks.patch b/backport-fix-mem-leaks.patch new file mode 100644 index 0000000000000000000000000000000000000000..d8e4fc7d4de0887f69591a8e222b90c133ae9735 --- /dev/null +++ b/backport-fix-mem-leaks.patch @@ -0,0 +1,147 @@ +From f3c1a4d7bb9485daf00f08f6971ead37c75b1098 Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Mon, 25 Mar 2024 11:22:28 +0800 +Subject: [PATCH 1/3] ln: fix memory leaks in do_link + +* src/ln.c (do_link): Free memory allocated by convert_abs_rel +on all code paths (Bug#47373). + +Upstream-commit: 6e98f67758260579d7d44ea5f2df4c82d28c9f58 +Signed-off-by: Kamil Dudka +--- + src/ln.c | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/src/ln.c b/src/ln.c +index ffa278e..f81bea8 100644 +--- a/src/ln.c ++++ b/src/ln.c +@@ -229,14 +229,14 @@ do_link (char const *source, int destdir_fd, char const *dest_base, + if (errno != ENOENT) + { + error (0, errno, _("failed to access %s"), quoteaf (dest)); +- return false; ++ goto fail; + } + force = false; + } + else if (S_ISDIR (dest_stats.st_mode)) + { + error (0, 0, _("%s: cannot overwrite directory"), quotef (dest)); +- return false; ++ goto fail; + } + else if (seen_file (dest_set, dest, &dest_stats)) + { +@@ -245,7 +245,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base, + error (0, 0, + _("will not overwrite just-created %s with %s"), + quoteaf_n (0, dest), quoteaf_n (1, source)); +- return false; ++ goto fail; + } + else + { +@@ -274,7 +274,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base, + { + error (0, 0, _("%s and %s are the same file"), + quoteaf_n (0, source), quoteaf_n (1, dest)); +- return false; ++ goto fail; + } + } + +@@ -285,7 +285,10 @@ do_link (char const *source, int destdir_fd, char const *dest_base, + fprintf (stderr, _("%s: replace %s? "), + program_name, quoteaf (dest)); + if (!yesno ()) +- return true; ++ { ++ free(rel_source); ++ return true; ++ } + } + + if (backup_type != no_backups) +@@ -304,7 +307,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base, + { + error (0, rename_errno, _("cannot backup %s"), + quoteaf (dest)); +- return false; ++ goto fail; + } + force = false; + } +@@ -397,6 +400,10 @@ do_link (char const *source, int destdir_fd, char const *dest_base, + free (backup_base); + free (rel_source); + return link_errno <= 0; ++ ++fail: ++ free (rel_source); ++ return false; + } + + void +-- +2.27.0 + + +From 9ba0fd3e0f9fa0057a7bcaa776a0f8195ecaea73 Mon Sep 17 00:00:00 2001 +From: Paul Eggert +Date: Mon, 25 Mar 2024 11:24:29 +0800 +Subject: [PATCH 2/3] hostname: use puts + +* src/hostname.c (main): Prefer puts to printf "%s\n". + +Upstream-commit: c7a588ac3632aae21642d4d568497177950d36bf +Signed-off-by: Kamil Dudka +--- + src/hostname.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/hostname.c b/src/hostname.c +index 0b5c0cf..62cc98c 100644 +--- a/src/hostname.c ++++ b/src/hostname.c +@@ -103,7 +103,7 @@ main (int argc, char **argv) + hostname = xgethostname (); + if (hostname == NULL) + die (EXIT_FAILURE, errno, _("cannot determine hostname")); +- printf ("%s\n", hostname); ++ puts (hostname); + } + + if (optind + 1 < argc) +-- +2.27.0 + + +From fafc84f3f0d965292791cdf6baa267febcb38419 Mon Sep 17 00:00:00 2001 +From: Paul Eggert +Date: Mon, 25 Mar 2024 11:25:35 +0800 +Subject: [PATCH 3/3] hostname: pacify valgrind + +* src/hostname.c (main) [IF_LINT]: Free hostname (Bug#47384). + +Upstream-commit: 4698e284f37844bc9b9f63f00eb556ccaaed5030 +Signed-off-by: Kamil Dudka +--- + src/hostname.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/hostname.c b/src/hostname.c +index 62cc98c..7210248 100644 +--- a/src/hostname.c ++++ b/src/hostname.c +@@ -104,6 +104,7 @@ main (int argc, char **argv) + if (hostname == NULL) + die (EXIT_FAILURE, errno, _("cannot determine hostname")); + puts (hostname); ++ IF_LINT (free (hostname)); + } + + if (optind + 1 < argc) +-- +2.27.0 + diff --git a/coreutils.spec b/coreutils.spec index ac6aa56c0a4b2b0693c8a6833a79752be10e840b..3c07702fe3c36bffaead11f61714134bc28af0ae 100644 --- a/coreutils.spec +++ b/coreutils.spec @@ -1,6 +1,6 @@ Name: coreutils Version: 8.32 -Release: 7 +Release: 8 License: GPLv3+ Summary: A set of basic GNU tools commonly used in shell scripts Url: https://www.gnu.org/software/coreutils/ @@ -39,6 +39,7 @@ Patch21: backport-ls-avoid-triggering-automounts.patch Patch22: backport-stat-only-automount-with-cached-never.patch Patch23: 0001-basenc-fix-bug49741-using-wrong-decoding-buffer-leng.patch Patch24: 0002-cat-with-E-fix-handling-of-r-n-spanning-buffers.patch +Patch25: backport-fix-mem-leaks.patch Conflicts: filesystem < 3 # To avoid clobbering installs @@ -157,6 +158,10 @@ fi %{_mandir}/man*/* %changelog +* Mon Mar 25 2024 cenhuilin - 8.32-8 +- sync patches from community +- add backport-fix-mem-leaks.patch + * Tue Nov 28 2023 liningjie - 8.32-7 - cat: with -E fix handling of \r\n spanning buffers