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

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