From 897b36fa9041311b8c459e47acfd3057022defcf Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Sat, 26 Feb 2011 20:20:10 +0000
Subject: [PATCH 10/24] 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 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

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()
-- 
1.6.2.2.646.gb214

