diff --git a/backport-fix-mem-leaks.patch b/backport-fix-mem-leaks.patch new file mode 100644 index 0000000000000000000000000000000000000000..7c1cb62311f8eb5c43e5603ef513b3a3f5136541 --- /dev/null +++ b/backport-fix-mem-leaks.patch @@ -0,0 +1,146 @@ +From e54ab6ec24442eb5414fef414f0ee815efb9a9bb Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Tue, 19 Mar 2024 17:07:52 +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..9b52602 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 e1422d781d0d9da3a92f28d7294a9c8a0e45f25a Mon Sep 17 00:00:00 2001 +From: Paul Eggert +Date: Tue, 19 Mar 2024 17:22:26 +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 76b29ef9909cc881b99de3dd5c34e90b03385a70 Mon Sep 17 00:00:00 2001 +From: Paul Eggert +Date: Tue, 19 Mar 2024 17:23:22 +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 c42f5396915001629dacb420509e54de05c04241..31ce352fa99d676f2531dacc59cb5aea1424ec23 100644 --- a/coreutils.spec +++ b/coreutils.spec @@ -1,6 +1,6 @@ Name: coreutils Version: 8.32 -Release: 10 +Release: 11 License: GPLv3+ Summary: A set of basic GNU tools commonly used in shell scripts Url: https://www.gnu.org/software/coreutils/ @@ -47,6 +47,7 @@ Patch29: backport-tac-handle-short-reads-on-input.patch Patch30: backport-setenv-Don-t-crash-if-malloc-returns-NULL.patch Patch31: backport-who-don-t-crash-if-clock-gyrates.patch Patch32: backport-doc-od-strings-clarify-operation.patch +Patch33: backport-fix-mem-leaks.patch Conflicts: filesystem < 3 # To avoid clobbering installs @@ -165,6 +166,10 @@ fi %{_mandir}/man*/* %changelog +* Tue Mar 19 2024 cenhuilin - 8.32-11 +- sync patches from community +- add backport-fix-mem-leaks.patch + * Tue Dec 5 2023 jiangchuangang - 8.32-10 - sync patches from community - add backport-who-fix-only-theoretical-overflow.patch