Blame SOURCES/sos-bz1998521-unpackaged-recursive-symlink.patch

900e1b
From e2ca3d02f36c0db4efaacfb2c1b7d502f38e371c Mon Sep 17 00:00:00 2001
900e1b
From: Pavel Moravec <pmoravec@redhat.com>
900e1b
Date: Mon, 30 Aug 2021 10:18:29 +0200
900e1b
Subject: [PATCH] [unpackaged] deal with recursive loop of symlinks properly
900e1b
900e1b
When the plugin processes a recursive loop of symlinks, it currently
900e1b
hangs in an infinite loop trying to follow the symlinks. Use
900e1b
pathlib.Path.resolve() method to return the target directly.
900e1b
900e1b
Resolves: #2664
900e1b
900e1b
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
900e1b
---
900e1b
 sos/report/plugins/unpackaged.py | 5 +++--
900e1b
 1 file changed, 3 insertions(+), 2 deletions(-)
900e1b
900e1b
diff --git a/sos/report/plugins/unpackaged.py b/sos/report/plugins/unpackaged.py
900e1b
index e5cc6191..9d68077c 100644
900e1b
--- a/sos/report/plugins/unpackaged.py
900e1b
+++ b/sos/report/plugins/unpackaged.py
900e1b
@@ -10,6 +10,7 @@ from sos.report.plugins import Plugin, RedHatPlugin
900e1b
 
900e1b
 import os
900e1b
 import stat
900e1b
+from pathlib import Path
900e1b
 
900e1b
 
900e1b
 class Unpackaged(Plugin, RedHatPlugin):
900e1b
@@ -41,8 +42,8 @@ class Unpackaged(Plugin, RedHatPlugin):
900e1b
                 for name in files:
900e1b
                     path = os.path.join(root, name)
900e1b
                     try:
900e1b
-                        while stat.S_ISLNK(os.lstat(path).st_mode):
900e1b
-                            path = os.path.abspath(os.readlink(path))
900e1b
+                        if stat.S_ISLNK(os.lstat(path).st_mode):
900e1b
+                            path = Path(path).resolve()
900e1b
                     except Exception:
900e1b
                         continue
900e1b
                     file_list.append(os.path.realpath(path))
900e1b
-- 
900e1b
2.31.1
900e1b