Brad Bishop | 220d553 | 2018-08-14 00:59:39 +0100 | [diff] [blame] | 1 | From ae65651eab053fc6dc4590dbb863a268215c1fc5 Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> |
| 3 | Date: Fri, 8 Jun 2018 11:45:40 +0100 |
| 4 | Subject: [PATCH] [PATCH] Remove existing files before overwriting them |
| 5 | |
| 6 | Archive should extract only the latest same-named entry. |
| 7 | Extracted regular file should not be writtent into existing block |
| 8 | device (or any other one). |
| 9 | |
| 10 | https://rt.cpan.org/Ticket/Display.html?id=125523 |
| 11 | |
| 12 | CVE: CVE-2018-12015 |
| 13 | Upstream-Status: Backport [https://github.com/jib/archive-tar-new/commit/ae65651eab053fc6dc4590dbb863a268215c1fc5] |
| 14 | |
| 15 | Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk> |
| 16 | Signed-off-by: Jagadeesh Krishnanjanappa <jkrishnanjanappa@mvista.com> |
| 17 | --- |
| 18 | lib/Archive/Tar.pm | 14 ++++++++++++++ |
| 19 | 1 file changed, 14 insertions(+) |
| 20 | |
| 21 | diff --git a/cpan/Archive-Tar/lib/Archive/Tar.pm b/cpan/Archive-Tar/lib/Archive/Tar.pm |
| 22 | index 6244369..a83975f 100644 |
| 23 | --- a/cpan/Archive-Tar/lib/Archive/Tar.pm |
| 24 | +++ b/cpan/Archive-Tar/lib/Archive/Tar.pm |
| 25 | @@ -845,6 +845,20 @@ sub _extract_file { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | + ### If a file system already contains a block device with the same name as |
| 30 | + ### the being extracted regular file, we would write the file's content |
| 31 | + ### to the block device. So remove the existing file (block device) now. |
| 32 | + ### If an archive contains multiple same-named entries, the last one |
| 33 | + ### should replace the previous ones. So remove the old file now. |
| 34 | + ### If the old entry is a symlink to a file outside of the CWD, the new |
| 35 | + ### entry would create a file there. This is CVE-2018-12015 |
| 36 | + ### <https://rt.cpan.org/Ticket/Display.html?id=125523>. |
| 37 | + if (-l $full || -e _) { |
| 38 | + if (!unlink $full) { |
| 39 | + $self->_error( qq[Could not remove old file '$full': $!] ); |
| 40 | + return; |
| 41 | + } |
| 42 | + } |
| 43 | if( length $entry->type && $entry->is_file ) { |
| 44 | my $fh = IO::File->new; |
| 45 | $fh->open( '>' . $full ) or ( |
| 46 | -- |
| 47 | 2.13.3 |
| 48 | |