]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer readlink to lstat in find_emacs_executable
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 24 Jul 2025 12:17:35 +0000 (05:17 -0700)
committerEshel Yaron <me@eshelyaron.com>
Fri, 25 Jul 2025 20:14:18 +0000 (22:14 +0200)
* src/emacs.c (find_emacs_executable): Prefer readlink to lstat
when testing whether a file is a symlink.  This avoids EOVERFLOW
issues.

(cherry picked from commit 67ea9485a65dee4fb654f1bc177c71028d020607)

src/emacs.c

index 1239bb7bfda7fb71ca3f6108af71cabf704894d3..0e10398dc78bd0def963d7b47a277e95682a0d74 100644 (file)
@@ -760,6 +760,7 @@ find_emacs_executable (char const *argv0, ptrdiff_t *candidate_size)
   return prog_fname ? xstrdup (prog_fname) : NULL;
 #else  /* !WINDOWSNT */
   char *candidate = NULL;
+  char linkbuf[1];
 
   /* If the executable name contains a slash, we have some kind of
      path already, so just resolve symlinks and return the result.  */
@@ -820,7 +821,7 @@ find_emacs_executable (char const *argv0, ptrdiff_t *candidate_size)
          /* People put on PATH a symlink to the real Emacs
             executable, with all the auxiliary files where the real
             executable lives.  Support that.  */
-         if (lstat (candidate, &st) == 0 && S_ISLNK (st.st_mode))
+         if (0 <= readlink (candidate, linkbuf, sizeof linkbuf))
            {
              char *real_name = realpath (candidate, NULL);