[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 31279f9 2/2: Make "emacs --script /dev/stdin work again when that
From: |
Lars Ingebrigtsen |
Subject: |
master 31279f9 2/2: Make "emacs --script /dev/stdin work again when that's a pipe |
Date: |
Thu, 11 Nov 2021 22:27:23 -0500 (EST) |
branch: master
commit 31279f92ae35f651d68104846268d64dadc6a943
Author: Bryan C. Mills <bcmills@google.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Make "emacs --script /dev/stdin work again when that's a pipe
* src/lread.c (Fload): Adjust callers.
* src/lread.c (safe_to_load_version): Check lseek errors
(Bug#48940).
Copyright-paperwork-exempt: yes
---
src/lread.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/lread.c b/src/lread.c
index b3f9e6f..39cab19 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1045,12 +1045,18 @@ lisp_file_lexically_bound_p (Lisp_Object readcharfun)
safe to load. Only files compiled with Emacs can be loaded. */
static int
-safe_to_load_version (int fd)
+safe_to_load_version (Lisp_Object file, int fd)
{
+ struct stat st;
char buf[512];
int nbytes, i;
int version = 1;
+ /* If the file is not regular, then we cannot safely seek it.
+ Assume that it is not safe to load as a compiled file. */
+ if (fstat(fd, &st) == 0 && !S_ISREG (st.st_mode))
+ return 0;
+
/* Read the first few bytes from the file, and look for a line
specifying the byte compiler version used. */
nbytes = emacs_read_quit (fd, buf, sizeof buf);
@@ -1068,7 +1074,9 @@ safe_to_load_version (int fd)
version = 0;
}
- lseek (fd, 0, SEEK_SET);
+ if (lseek (fd, 0, SEEK_SET) < 0)
+ report_file_error ("Seeking to start of file", file);
+
return version;
}
@@ -1401,7 +1409,7 @@ Return t if the file exists and loads successfully. */)
if (is_elc
/* version = 1 means the file is empty, in which case we can
treat it as not byte-compiled. */
- || (fd >= 0 && (version = safe_to_load_version (fd)) > 1))
+ || (fd >= 0 && (version = safe_to_load_version (file, fd)) > 1))
/* Load .elc files directly, but not when they are
remote and have no handler! */
{
@@ -1411,7 +1419,7 @@ Return t if the file exists and loads successfully. */)
int result;
if (version < 0
- && ! (version = safe_to_load_version (fd)))
+ && ! (version = safe_to_load_version (file, fd)))
{
error ("File `%s' was not compiled in Emacs", SDATA (found));
}