git » libjio » commit 897b36f

tests/stress: Check the file we're going to use does not exist

author Alberto Bertogli
2011-02-26 20:20:10 UTC
committer Alberto Bertogli
2011-02-26 20:20:10 UTC
parent a894011dc4e9daed1f6bacbac7ee987e2c894668

tests/stress: Check the file we're going to use does not exist

Since jiostress overrides the file, and it's not useful to run it on already
created files, make it check if the file exists before using it, to prevent
accidental destruction.

This also helps to prevent symlink exploits when used with temporary paths.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

tests/stress/jiostress +7 -0

diff --git a/tests/stress/jiostress b/tests/stress/jiostress
index 8f0773e..5584023 100755
--- a/tests/stress/jiostress
+++ b/tests/stress/jiostress
@@ -680,6 +680,13 @@ def main():
 	if not options.use_internal_locks:
 		options.do_verify = False
 
+
+	# Open the file with O_EXCL here to make sure we're the ones creating
+	# it, to avoid stepping over existing files, and also prevent security
+	# issues with temporary files. We discard the file descriptor, as
+	# we're not really interested in it here, we just wanted the file.
+	_ = os.open(fname, os.O_RDWR | os.O_CREAT | os.O_EXCL, 0o600)
+
 	output = OutputHandler(every = 2)
 	if options.use_internal_locks:
 		lockmgr = LockManager()