Blame SOURCES/rig-full-random-temp.patch

7d5202
From 90c5505d82b288bbc0b2e8b01e85b78d18a0bd18 Mon Sep 17 00:00:00 2001
7d5202
From: Jake Hunsaker <jhunsake@redhat.com>
7d5202
Date: Thu, 9 Jun 2022 14:26:02 -0400
7d5202
Subject: [PATCH] [rig] Use `tempfile` module for temp directory creation
7d5202
7d5202
Previously, a change was made to temp directory creation in an effort to
7d5202
make it more secure. While that was largely handled, it left us with an
7d5202
unhandled error in an edge case configuration. Rather than putting a
7d5202
band-aid over that again, re-write the temp directory creation process
7d5202
to leverage the `tempfile` module, so that we can safely and completely
7d5202
ignore the id/name of a rig, and leave the use of that for the
7d5202
communication socket.
7d5202
7d5202
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
7d5202
---
7d5202
 rigging/rigs/__init__.py | 13 +++++++------
7d5202
 1 file changed, 7 insertions(+), 6 deletions(-)
7d5202
7d5202
diff --git a/rigging/rigs/__init__.py b/rigging/rigs/__init__.py
7d5202
index f14f312..29bb8b4 100644
7d5202
--- a/rigging/rigs/__init__.py
7d5202
+++ b/rigging/rigs/__init__.py
7d5202
@@ -18,6 +18,7 @@ import string
7d5202
 import socket
7d5202
 import sys
7d5202
 import tarfile
7d5202
+import tempfile
7d5202
 import time
7d5202
 
7d5202
 from argparse import Action
7d5202
@@ -110,7 +111,7 @@ class BaseRig():
7d5202
             self.log_debug("Initializing %s rig %s" %
7d5202
                            (self.resource_name, self.id))
7d5202
             self._sock, self._sock_address = self._create_rig_socket()
7d5202
-            self._tmp_dir = self._create_temp_dir()
7d5202
+            self._create_temp_dir()
7d5202
             self.files = []
7d5202
 
7d5202
     def set_rig_id(self):
7d5202
@@ -196,11 +197,11 @@ class BaseRig():
7d5202
         Create a temp directory for rig to use for saving created files too
7d5202
         """
7d5202
         try:
7d5202
-            _dir = "%s.%s/" % (RIG_TMP_DIR_PREFIX, self.id)
7d5202
-            os.makedirs(_dir)
7d5202
-            return _dir
7d5202
-        except OSError:
7d5202
-            raise CannotConfigureRigError('failed to create temp directory')
7d5202
+            self._tmp_dir = tempfile.mkdtemp(prefix='rig.', dir='/var/tmp')
7d5202
+        except Exception as err:
7d5202
+            raise CannotConfigureRigError(
7d5202
+                "failed to create temp directory: %s" % err
7d5202
+            )
7d5202
 
7d5202
     def _load_args(self):
7d5202
         """
7d5202
-- 
7d5202
2.35.3
7d5202