Bug 31793 - tools-utils: Avoid endless loop in is_regular_file for directories

Message ID 87r0dit0as.fsf@redhat.com
State New
Headers
Series Bug 31793 - tools-utils: Avoid endless loop in is_regular_file for directories |

Commit Message

Dodji Seketeli May 31, 2024, 4:26 p.m. UTC
  Hello,

Claudio Claudiu Zissulescu Ianculescu reported that 'abidw --linux-tree /some/linux/kernel/tree'
is crashing: https://sourceware.org/bugzilla/show_bug.cgi?id=31793.

This due to the fact that when is_regular_file is given a directory, it
loops endlessly.  Oops.

Fixed thus.

	* src/abg-tools-utils.cc (is_regular_file): Loop on symbolic links
	only.

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

Patch

diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc
index 6d6ab054..95bd0be5 100644
--- a/src/abg-tools-utils.cc
+++ b/src/abg-tools-utils.cc
@@ -416,9 +416,12 @@  is_regular_file(const string& path)
   if (S_ISREG(st.st_mode))
     return true;
 
-  string symlink_target_path;
-  if (maybe_get_symlink_target_file_path(path, symlink_target_path))
-    return is_regular_file(symlink_target_path);
+  if (S_ISLNK(st.st_mode))
+    {
+      string symlink_target_path;
+      if (maybe_get_symlink_target_file_path(path, symlink_target_path))
+	return is_regular_file(symlink_target_path);
+    }
 
   return false;
 }