6f6bbd
From f0ada4fd4d9f4a6c028f86306e62fe880949d4e1 Mon Sep 17 00:00:00 2001
6f6bbd
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
6f6bbd
Date: Wed, 27 Nov 2013 10:58:07 +0100
6f6bbd
Subject: [PATCH] Do not use already existing temporary files
6f6bbd
MIME-Version: 1.0
6f6bbd
Content-Type: text/plain; charset=UTF-8
6f6bbd
Content-Transfer-Encoding: 8bit
6f6bbd
6f6bbd
mirror() method tries to create a new temporary file as can be
6f6bbd
concluded by using random name.
6f6bbd
6f6bbd
To prevent from from attacks, one has to make sure the file does not
6f6bbd
exist. This patch creates temporary files with O_CREAT|O_EXCL mode.
6f6bbd
6f6bbd
Signed-off-by: Petr Písař <ppisar@redhat.com>
6f6bbd
---
6f6bbd
 lib/HTTP/Tiny.pm | 5 +++--
6f6bbd
 1 file changed, 3 insertions(+), 2 deletions(-)
6f6bbd
6f6bbd
diff --git a/lib/HTTP/Tiny.pm b/lib/HTTP/Tiny.pm
6f6bbd
index 8736816..6ee800e 100644
6f6bbd
--- a/lib/HTTP/Tiny.pm
6f6bbd
+++ b/lib/HTTP/Tiny.pm
6f6bbd
@@ -6,6 +6,7 @@ use warnings;
6f6bbd
 our $VERSION = '0.033'; # VERSION
6f6bbd
 
6f6bbd
 use Carp ();
6f6bbd
+use Fcntl ();
6f6bbd
 
6f6bbd
 
6f6bbd
 my @attributes;
6f6bbd
@@ -113,8 +114,8 @@ sub mirror {
6f6bbd
         $args->{headers}{'if-modified-since'} ||= $self->_http_date($mtime);
6f6bbd
     }
6f6bbd
     my $tempfile = $file . int(rand(2**31));
6f6bbd
-    open my $fh, ">", $tempfile
6f6bbd
-        or Carp::croak(qq/Error: Could not open temporary file $tempfile for downloading: $!\n/);
6f6bbd
+    sysopen my $fh, $tempfile, Fcntl::O_CREAT|Fcntl::O_EXCL|Fcntl::O_WRONLY
6f6bbd
+        or Carp::croak(qq/Error: Could not create temporary file $tempfile for downloading: $!\n/);
6f6bbd
     binmode $fh;
6f6bbd
     $args->{data_callback} = sub {
6f6bbd
         print {$fh} $_[0]
6f6bbd
-- 
6f6bbd
1.8.3.1
6f6bbd