[06/16] tools-utils: Avoid endless loop

Message ID 87r0naf6ex.fsf@redhat.com
State New
Headers
Series Fixing various issues found while working on PR30309 |

Commit Message

Dodji Seketeli Sept. 7, 2023, 1:40 p.m. UTC
  Heloo,

	* src/abg-tools-utils.cc (is_dir): Avoid endless loop.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to master.
---
 src/abg-tools-utils.cc | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
  

Patch

diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc
index 62a0ebb1..e7155846 100644
--- a/src/abg-tools-utils.cc
+++ b/src/abg-tools-utils.cc
@@ -567,10 +567,18 @@  is_dir(const string& path)
   if (S_ISDIR(st.st_mode))
     return true;
 
-  string symlink_target_path;
-  if (maybe_get_symlink_target_file_path(path, symlink_target_path))
-    return is_dir(symlink_target_path);
+  if (S_ISLNK(st.st_mode))
+    {
+      string symlink_target_path;
+      if (maybe_get_symlink_target_file_path(path, symlink_target_path))
+	{
+	  if (!get_stat(path, &st))
+	    return false;
 
+	  if (S_ISDIR(st.st_mode))
+	    return true;
+	}
+    }
   return false;
 }