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

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