From: Paul Eggert Date: Thu, 24 Jul 2025 12:17:35 +0000 (-0700) Subject: Prefer readlink to lstat in find_emacs_executable X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=db179c7aacb63a11271a5a0932734011a7edb5bb;p=emacs.git Prefer readlink to lstat in find_emacs_executable * 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) --- diff --git a/src/emacs.c b/src/emacs.c index 1239bb7bfda..0e10398dc78 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -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);