Blame SOURCES/sharutils-4.15.2-Fix-a-heap-buffer-overflow-in-find_archive.patch

80e372
From 1067cdba6d08f2a765cb0ea371189a5b703eb4db Mon Sep 17 00:00:00 2001
80e372
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
80e372
Date: Thu, 22 Feb 2018 16:39:43 +0100
80e372
Subject: [PATCH] Fix a heap-buffer-overflow in find_archive()
80e372
MIME-Version: 1.0
80e372
Content-Type: text/plain; charset=UTF-8
80e372
Content-Transfer-Encoding: 8bit
80e372
80e372
rw_buffer has allocated rw_base_size bytes. But subsequend fgets() in
80e372
find_archive() reads up-to BUFSIZ bytes.
80e372
80e372
On my system, BUFSIZ is 8192. rw_base_size is usually equaled to
80e372
a memory page size, 4096 on my system. Thus find_archive() can write
80e372
beyonded allocated memmory for rw_buffer array:
80e372
80e372
$ valgrind -- ./unshar /tmp/id\:000000\,sig\:06\,src\:000005+000030\,op\:splice\,rep\:4
80e372
==30582== Memcheck, a memory error detector
80e372
==30582== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
80e372
==30582== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
80e372
==30582== Command: ./unshar /tmp/id:000000,sig:06,src:000005+000030,op:splice,rep:4
80e372
==30582==
80e372
==30582== Invalid write of size 1
80e372
==30582==    at 0x4EAB480: _IO_getline_info (in /usr/lib64/libc-2.27.so)
80e372
==30582==    by 0x4EB47C2: fgets_unlocked (in /usr/lib64/libc-2.27.so)
80e372
==30582==    by 0x10BF60: fgets_unlocked (stdio2.h:320)
80e372
==30582==    by 0x10BF60: find_archive (unshar.c:243)
80e372
==30582==    by 0x10BF60: unshar_file (unshar.c:379)
80e372
==30582==    by 0x10BCCC: validate_fname (unshar-opts.c:604)
80e372
==30582==    by 0x10BCCC: main (unshar-opts.c:639)
80e372
==30582==  Address 0x523a790 is 0 bytes after a block of size 4,096 alloc'd
80e372
==30582==    at 0x4C2DBBB: malloc (vg_replace_malloc.c:299)
80e372
==30582==    by 0x10C670: init_unshar (unshar.c:450)
80e372
==30582==    by 0x10BC55: main (unshar-opts.c:630)
80e372
80e372
This was reported in
80e372
<http://lists.gnu.org/archive/html/bug-gnu-utils/2018-02/msg00004.html>.
80e372
80e372
Signed-off-by: Petr Písař <ppisar@redhat.com>
80e372
---
80e372
 src/unshar.c | 2 +-
80e372
 1 file changed, 1 insertion(+), 1 deletion(-)
80e372
80e372
diff --git a/src/unshar.c b/src/unshar.c
80e372
index 80bc3a9..0fc3773 100644
80e372
--- a/src/unshar.c
80e372
+++ b/src/unshar.c
80e372
@@ -240,7 +240,7 @@ find_archive (char const * name, FILE * file, off_t start)
80e372
       off_t position = ftello (file);
80e372
 
80e372
       /* Read next line, fail if no more and no previous process.  */
80e372
-      if (!fgets (rw_buffer, BUFSIZ, file))
80e372
+      if (!fgets (rw_buffer, rw_base_size, file))
80e372
 	{
80e372
 	  if (!start)
80e372
 	    error (0, 0, _("Found no shell commands in %s"), name);
80e372
-- 
80e372
2.13.6
80e372