0001-PATCH-Remove-existing-files-before-overwriting-them.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. Archive should extract only the latest same-named entry.
  6. Extracted regular file should not be writtent into existing block
  7. device (or any other one).
  8. https://rt.cpan.org/Ticket/Display.html?id=125523
  9. [Peter: rewrite path to match perl tarball with sed 's|\(lib/Archive\)|cpan/Archive-Tar/\1|g']
  10. Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
  11. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  12. ---
  13. cpan/Archive-Tar/lib/Archive/Tar.pm | 14 ++++++++++++++
  14. 1 file changed, 14 insertions(+)
  15. diff --git a/cpan/Archive-Tar/lib/Archive/Tar.pm b/cpan/Archive-Tar/lib/Archive/Tar.pm
  16. index 6244369..a83975f 100644
  17. --- a/cpan/Archive-Tar/lib/Archive/Tar.pm
  18. +++ b/cpan/Archive-Tar/lib/Archive/Tar.pm
  19. @@ -845,6 +845,20 @@ sub _extract_file {
  20. return;
  21. }
  22. + ### If a file system already contains a block device with the same name as
  23. + ### the being extracted regular file, we would write the file's content
  24. + ### to the block device. So remove the existing file (block device) now.
  25. + ### If an archive contains multiple same-named entries, the last one
  26. + ### should replace the previous ones. So remove the old file now.
  27. + ### If the old entry is a symlink to a file outside of the CWD, the new
  28. + ### entry would create a file there. This is CVE-2018-12015
  29. + ### <https://rt.cpan.org/Ticket/Display.html?id=125523>.
  30. + if (-l $full || -e _) {
  31. + if (!unlink $full) {
  32. + $self->_error( qq[Could not remove old file '$full': $!] );
  33. + return;
  34. + }
  35. + }
  36. if( length $entry->type && $entry->is_file ) {
  37. my $fh = IO::File->new;
  38. $fh->open( $full, '>' ) or (
  39. --
  40. 2.11.0