!19 fix unlikely memory leak

From: @zhangruifang2020 
Reviewed-by: @openeuler-basic 
Signed-off-by: @openeuler-basic
This commit is contained in:
openeuler-ci-bot 2022-10-19 08:02:06 +00:00 committed by Gitee
commit a20f8ff888
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 49 additions and 1 deletions

View File

@ -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 <zhangruifang1@h-partners.com> - 3.8-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix unlikely memory leak
* Tue Mar 22 2022 panxiaohe<panxh.life@foxmail.com> - 3.8-2
- Type:bugfix
- ID:NA

View File

@ -0,0 +1,41 @@
From f2e2b4d3c3288e6cae3918fc432bdab8c0c485b7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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.
Dont 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