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

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