From a232edb74aa0eefa058cc2ffa4eec7daf677dc9f Mon Sep 17 00:00:00 2001 From: zhangruifang2020 Date: Wed, 19 Oct 2022 10:14:08 +0800 Subject: [PATCH] fix unlikely memory leak --- diffutils.spec | 9 +++++- sdiff-fix-unlikely-memory-leak.patch | 41 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 sdiff-fix-unlikely-memory-leak.patch diff --git a/diffutils.spec b/diffutils.spec index 07254cc..7a8cd85 100644 --- a/diffutils.spec +++ b/diffutils.spec @@ -1,12 +1,13 @@ Name: diffutils Version: 3.8 -Release: 2 +Release: 3 Summary: A GNU collection of diff utilities URL: http://www.gnu.org/software/diffutils/diffutils.html Source: ftp://ftp.gnu.org/gnu/diffutils/diffutils-%{version}.tar.xz Patch1: diffutils-cmp-s-empty.patch Patch2: diffutils-i18n.patch Patch3: diff3-set-flagging-to-true-in-X-option.patch +Patch4: sdiff-fix-unlikely-memory-leak.patch License: GPLv3+ Provides: bundled(gnulib) @@ -55,6 +56,12 @@ cat tests/test-suite.log %exclude %{_infodir}/dir %changelog +* Wed Oct 19 2022 zhangruifang - 3.8-3 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix unlikely memory leak + * Tue Mar 22 2022 panxiaohe - 3.8-2 - Type:bugfix - ID:NA diff --git a/sdiff-fix-unlikely-memory-leak.patch b/sdiff-fix-unlikely-memory-leak.patch new file mode 100644 index 0000000..c843cd0 --- /dev/null +++ b/sdiff-fix-unlikely-memory-leak.patch @@ -0,0 +1,41 @@ +From f2e2b4d3c3288e6cae3918fc432bdab8c0c485b7 Mon Sep 17 00:00:00 2001 +From: Paul Eggert +Date: Sun, 22 Aug 2021 13:54:04 -0700 +Subject: [PATCH] sdiff: fix unlikely memory leak +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +* src/sdiff.c (temporary_file): Fix memory leak when mkstemp fails. +Don’t assume temporary file name length fits in ‘int’. +--- + src/sdiff.c | 13 ++++++++----- + 1 file changed, 8 insertions(+), 5 deletions(-) + +diff --git a/src/sdiff.c b/src/sdiff.c +index 11e4da9..ab12987 100644 +--- a/src/sdiff.c ++++ b/src/sdiff.c +@@ -1163,11 +1163,14 @@ temporary_file (void) + { + char const *tmpdir = getenv (TMPDIR_ENV); + char const *dir = tmpdir ? tmpdir : P_tmpdir; +- char *buf = xmalloc (strlen (dir) + 1 + 5 + 6 + 1); +- int fd; +- sprintf (buf, "%s/sdiffXXXXXX", dir); +- fd = mkstemp (buf); +- if (0 <= fd) ++ size_t dirlen = strlen (dir); ++ char *buf = xmalloc (dirlen + 1 + 5 + 6 + 1); ++ memcpy (buf, dir, dirlen); ++ strcpy (buf + dirlen, "/sdiffXXXXXX"); ++ int fd = mkstemp (buf); ++ if (fd < 0) ++ free (buf); ++ else + tmpname = buf; + return fd; + } +-- +2.27.0 + -- Gitee