summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2024-06-11 16:13:27 +0900
committerKoichi Sasada <ko1@atdot.net>2024-06-11 17:02:27 +0900
commit6086bae5c85cc297003012afc9cf5966fc75746a (patch)
tree50e02f3dd8fe59fd9574dab0cc752b11561d0cec
parentf0001a4fa7260d0c39e9ddba162f51c549cba2f8 (diff)
check `SPEC_TEMP_DIR` is world-writable or not
``` 1) Dir.mktmpdir when passed a block yields the path to the passed block ERROR ArgumentError: parent directory is world writable but not sticky: /tmp/rubytest.wlu5cs_11 /tmp/ruby/src/trunk/lib/tmpdir.rb:113:in 'Dir.mktmpdir' /tmp/ruby/src/trunk/spec/ruby/library/tmpdir/dir/mktmpdir_spec.rb:39:in 'block (2 levels) in <top (required)>' ``` This weird error comes from world-writable (and not sticky) directory of `SPEC_TEMP_DIR`. This patch checks `SPEC_TEMP_DIR` is not world-writable if exists and `File.umask` contains o+w mask.
-rw-r--r--spec/mspec/lib/mspec/helpers/tmp.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/spec/mspec/lib/mspec/helpers/tmp.rb b/spec/mspec/lib/mspec/helpers/tmp.rb
index 4c0eddab75..437261a6d0 100644
--- a/spec/mspec/lib/mspec/helpers/tmp.rb
+++ b/spec/mspec/lib/mspec/helpers/tmp.rb
@@ -36,7 +36,18 @@ all specs are cleaning up temporary files:
end
def tmp(name, uniquify = true)
- mkdir_p SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR
+ if Dir.exist? SPEC_TEMP_DIR
+ stat = File.stat(SPEC_TEMP_DIR)
+ if stat.world_writable? and !stat.sticky?
+ raise ArgumentError, "SPEC_TEMP_DIR (#{SPEC_TEMP_DIR}) is world writable but not sticky"
+ end
+ else
+ umask = File.umask
+ if (umask & 0002) == 0 # o+w
+ raise ArgumentError, "File.umask #=> #{umask.to_s(8)} (world-writable)"
+ end
+ mkdir_p SPEC_TEMP_DIR
+ end
if uniquify and !name.empty?
slash = name.rindex "/"