I couldn't get this to overflow the stack, since passing a large file
name will run into ENAMETOOLONG errors before find_mount_point is
executed. But as far as I can tell, this strdupa call was never needed.

-- 8< --

* src/find-mount-point.c (find_mount_point): Don't call ASSIGN_STRDUPA
on the result of dir_name.
---
 src/find-mount-point.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/find-mount-point.c b/src/find-mount-point.c
index 6624f7f75..f1666c93f 100644
--- a/src/find-mount-point.c
+++ b/src/find-mount-point.c
@@ -52,14 +52,12 @@ find_mount_point (char const *file, struct stat const 
*file_stat)
   else
     /* FILE is some other kind of file; use its directory.  */
     {
-      char *xdir = dir_name (file);
-      char *dir;
-      ASSIGN_STRDUPA (dir, xdir);
-      free (xdir);
+      char *dir = dir_name (file);
 
       if (chdir (dir) < 0)
         {
           error (0, errno, _("cannot change to directory %s"), quoteaf (dir));
+          free (dir);
           return NULL;
         }
 
@@ -67,8 +65,11 @@ find_mount_point (char const *file, struct stat const 
*file_stat)
         {
           error (0, errno, _("cannot stat current directory (now %s)"),
                  quoteaf (dir));
+          free (dir);
           goto done;
         }
+
+      free (dir);
     }
 
   /* Now walk up FILE's parents until we find another file system or /,
-- 
2.52.0


Reply via email to