summaryrefslogtreecommitdiff
path: root/src/lread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lread.c')
-rw-r--r--src/lread.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lread.c b/src/lread.c
index 9bb5f66adf3..5a2f1bc54e5 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;
}
@@ -1407,7 +1415,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! */
{
@@ -1416,11 +1424,8 @@ Return t if the file exists and loads successfully. */)
struct stat s1, s2;
int result;
- if (version < 0
- && ! (version = safe_to_load_version (fd)))
- {
- error ("File `%s' was not compiled in Emacs", SDATA (found));
- }
+ if (version < 0 && !(version = safe_to_load_version (file, fd)))
+ error ("File `%s' was not compiled in Emacs", SDATA (found));
compiled = 1;
@@ -2710,7 +2715,7 @@ read_escape (Lisp_Object readcharfun, bool stringp)
c = read_escape (readcharfun, 0);
if ((c & ~CHAR_MODIFIER_MASK) == '?')
return 0177 | (c & CHAR_MODIFIER_MASK);
- else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
+ else if (! ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
return c | ctrl_modifier;
/* ASCII control chars are made from letters (both cases),
as well as the non-letters within 0100...0137. */