diff options
author | Pavel Moravec <pmoravec@redhat.com> | 2021-08-30 10:18:29 +0200 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2021-08-31 11:35:19 -0400 |
commit | e2ca3d02f36c0db4efaacfb2c1b7d502f38e371c (patch) | |
tree | 7e6b9e6498dde8236012f1bdd98960cacd086fc1 | |
parent | b09ed75b09075d86c184b0a63cce9260f2cee4ca (diff) | |
download | sos-e2ca3d02f36c0db4efaacfb2c1b7d502f38e371c.tar.gz |
[unpackaged] deal with recursive loop of symlinks properly
When the plugin processes a recursive loop of symlinks, it currently
hangs in an infinite loop trying to follow the symlinks. Use
pathlib.Path.resolve() method to return the target directly.
Resolves: #2664
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r-- | sos/report/plugins/unpackaged.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/sos/report/plugins/unpackaged.py b/sos/report/plugins/unpackaged.py index e5cc6191..9d68077c 100644 --- a/sos/report/plugins/unpackaged.py +++ b/sos/report/plugins/unpackaged.py @@ -10,6 +10,7 @@ from sos.report.plugins import Plugin, RedHatPlugin import os import stat +from pathlib import Path class Unpackaged(Plugin, RedHatPlugin): @@ -41,8 +42,8 @@ class Unpackaged(Plugin, RedHatPlugin): for name in files: path = os.path.join(root, name) try: - while stat.S_ISLNK(os.lstat(path).st_mode): - path = os.path.abspath(os.readlink(path)) + if stat.S_ISLNK(os.lstat(path).st_mode): + path = Path(path).resolve() except Exception: continue file_list.append(os.path.realpath(path)) |