From 024f7a8c8c780b6eae4f952dd6ef86dca8036cb6 Mon Sep 17 00:00:00 2001 From: Terry Scheingeld Date: Wed, 11 Dec 2019 11:24:59 -0500 Subject: tmpio: workaround File#path being tainted on unlink Ruby mistakenly taints the file path, causing File.unlink to fail: https://bugs.ruby-lang.org/issues/14485 Workaround the Ruby bug by keeping the path as a local variable and passing that to File.unlink, instead of the return value of File#path. Link: https://bogomips.org/unicorn-public/CABg1sXrvGv9G6CDQxePDUqTe6N-5UpLXm7eG3YQO=dda-Cgg7A@mail.gmail.com/ --- lib/unicorn/tmpio.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/unicorn/tmpio.rb b/lib/unicorn/tmpio.rb index db88ed3..0bbf6ec 100644 --- a/lib/unicorn/tmpio.rb +++ b/lib/unicorn/tmpio.rb @@ -11,12 +11,18 @@ class Unicorn::TmpIO < File # immediately, switched to binary mode, and userspace output # buffering is disabled def self.new + path = nil + + # workaround File#path being tainted: + # https://bugs.ruby-lang.org/issues/14485 fp = begin - super("#{Dir::tmpdir}/#{rand}", RDWR|CREAT|EXCL, 0600) + path = "#{Dir::tmpdir}/#{rand}" + super(path, RDWR|CREAT|EXCL, 0600) rescue Errno::EEXIST retry end - unlink(fp.path) + + unlink(path) fp.binmode fp.sync = true fp -- cgit v1.2.3-24-ge0c7