diff options
| author | Gerd Moellmann | 2000-03-15 19:57:38 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-03-15 19:57:38 +0000 |
| commit | da84f340a4e0e097638464e50035d1bd4804fa51 (patch) | |
| tree | 60989aab1d9492a5a456c797ffa1d8445cf4fb72 /src | |
| parent | 81c7ca6923ca9431e92c76da199b08531d685da0 (diff) | |
| download | emacs-da84f340a4e0e097638464e50035d1bd4804fa51.tar.gz emacs-da84f340a4e0e097638464e50035d1bd4804fa51.zip | |
(load_dangerous_libraries): New variable.
(Vbytecomp_version_regexp): New variable.
(safe_to_load_p): New function.
(Fload): Handle files not compiled with Emacs specially.
(syms_of_lread): New Lisp variable load-dangerous-libraries.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/src/lread.c b/src/lread.c index d6402b38da3..5e373bee9a2 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -535,6 +535,52 @@ static void readevalloop (); | |||
| 535 | static Lisp_Object load_unwind (); | 535 | static Lisp_Object load_unwind (); |
| 536 | static Lisp_Object load_descriptor_unwind (); | 536 | static Lisp_Object load_descriptor_unwind (); |
| 537 | 537 | ||
| 538 | /* Non-zero means load dangerous compiled Lisp files. */ | ||
| 539 | |||
| 540 | int load_dangerous_libraries; | ||
| 541 | |||
| 542 | /* A regular expression used to detect files compiled with Emacs. */ | ||
| 543 | |||
| 544 | static Lisp_Object Vbytecomp_version_regexp; | ||
| 545 | |||
| 546 | |||
| 547 | /* Value is non-zero if the file asswociated with file descriptor FD | ||
| 548 | is a compiled Lisp file that's safe to load. Only files compiled | ||
| 549 | with Emacs are safe to load. Files compiled with XEmacs can lead | ||
| 550 | to a crash in Fbyte_code because of an incompatible change in the | ||
| 551 | byte compiler. */ | ||
| 552 | |||
| 553 | static int | ||
| 554 | safe_to_load_p (fd) | ||
| 555 | int fd; | ||
| 556 | { | ||
| 557 | char buf[512]; | ||
| 558 | int nbytes, i; | ||
| 559 | int safe_p = 1; | ||
| 560 | |||
| 561 | /* Read the first few bytes from the file, and look for a line | ||
| 562 | specifying the byte compiler version used. */ | ||
| 563 | nbytes = emacs_read (fd, buf, sizeof buf - 1); | ||
| 564 | if (nbytes > 0) | ||
| 565 | { | ||
| 566 | buf[nbytes] = '\0'; | ||
| 567 | |||
| 568 | /* Skip to the next newline, skipping over the initial `ELC' | ||
| 569 | with NUL bytes following it. */ | ||
| 570 | for (i = 0; i < nbytes && buf[i] != '\n'; ++i) | ||
| 571 | ; | ||
| 572 | |||
| 573 | if (i < nbytes | ||
| 574 | && fast_c_string_match_ignore_case (Vbytecomp_version_regexp, | ||
| 575 | buf + i) < 0) | ||
| 576 | safe_p = 0; | ||
| 577 | } | ||
| 578 | |||
| 579 | lseek (fd, 0, SEEK_SET); | ||
| 580 | return safe_p; | ||
| 581 | } | ||
| 582 | |||
| 583 | |||
| 538 | DEFUN ("load", Fload, Sload, 1, 5, 0, | 584 | DEFUN ("load", Fload, Sload, 1, 5, 0, |
| 539 | "Execute a file of Lisp code named FILE.\n\ | 585 | "Execute a file of Lisp code named FILE.\n\ |
| 540 | First try FILE with `.elc' appended, then try with `.el',\n\ | 586 | First try FILE with `.elc' appended, then try with `.el',\n\ |
| @@ -569,6 +615,7 @@ Return t if file exists.") | |||
| 569 | #ifdef DOS_NT | 615 | #ifdef DOS_NT |
| 570 | fmode = "rt"; | 616 | fmode = "rt"; |
| 571 | #endif /* DOS_NT */ | 617 | #endif /* DOS_NT */ |
| 618 | int safe_p = 1; | ||
| 572 | 619 | ||
| 573 | CHECK_STRING (file, 0); | 620 | CHECK_STRING (file, 0); |
| 574 | 621 | ||
| @@ -649,6 +696,16 @@ Return t if file exists.") | |||
| 649 | struct stat s1, s2; | 696 | struct stat s1, s2; |
| 650 | int result; | 697 | int result; |
| 651 | 698 | ||
| 699 | if (!safe_to_load_p (fd)) | ||
| 700 | { | ||
| 701 | safe_p = 0; | ||
| 702 | if (!load_dangerous_libraries) | ||
| 703 | error ("File `%s' was not compiled in Emacs", | ||
| 704 | XSTRING (found)->data); | ||
| 705 | else if (!NILP (nomessage)) | ||
| 706 | message_with_string ("File `%s' not compiled in Emacs", found, 1); | ||
| 707 | } | ||
| 708 | |||
| 652 | compiled = 1; | 709 | compiled = 1; |
| 653 | 710 | ||
| 654 | #ifdef DOS_NT | 711 | #ifdef DOS_NT |
| @@ -671,6 +728,8 @@ Return t if file exists.") | |||
| 671 | } | 728 | } |
| 672 | else | 729 | else |
| 673 | { | 730 | { |
| 731 | load_source: | ||
| 732 | |||
| 674 | /* We are loading a source file (*.el). */ | 733 | /* We are loading a source file (*.el). */ |
| 675 | if (!NILP (Vload_source_file_function)) | 734 | if (!NILP (Vload_source_file_function)) |
| 676 | { | 735 | { |
| @@ -699,7 +758,10 @@ Return t if file exists.") | |||
| 699 | 758 | ||
| 700 | if (NILP (nomessage)) | 759 | if (NILP (nomessage)) |
| 701 | { | 760 | { |
| 702 | if (!compiled) | 761 | if (!safe_p) |
| 762 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...", | ||
| 763 | file, 1); | ||
| 764 | else if (!compiled) | ||
| 703 | message_with_string ("Loading %s (source)...", file, 1); | 765 | message_with_string ("Loading %s (source)...", file, 1); |
| 704 | else if (newer) | 766 | else if (newer) |
| 705 | message_with_string ("Loading %s (compiled; note, source file is newer)...", | 767 | message_with_string ("Loading %s (compiled; note, source file is newer)...", |
| @@ -740,7 +802,10 @@ Return t if file exists.") | |||
| 740 | 802 | ||
| 741 | if (!noninteractive && NILP (nomessage)) | 803 | if (!noninteractive && NILP (nomessage)) |
| 742 | { | 804 | { |
| 743 | if (!compiled) | 805 | if (!safe_p) |
| 806 | message_with_string ("Loading %s (compiled; note unsafe, not compiled in Emacs)...done", | ||
| 807 | file, 1); | ||
| 808 | else if (!compiled) | ||
| 744 | message_with_string ("Loading %s (source)...done", file, 1); | 809 | message_with_string ("Loading %s (source)...done", file, 1); |
| 745 | else if (newer) | 810 | else if (newer) |
| 746 | message_with_string ("Loading %s (compiled; note, source file is newer)...done", | 811 | message_with_string ("Loading %s (compiled; note, source file is newer)...done", |
| @@ -3351,6 +3416,16 @@ You cannot count on them to still be there!"); | |||
| 3351 | "List of all DEFVAR_BOOL variables, used by the byte code optimizer."); | 3416 | "List of all DEFVAR_BOOL variables, used by the byte code optimizer."); |
| 3352 | Vbyte_boolean_vars = Qnil; | 3417 | Vbyte_boolean_vars = Qnil; |
| 3353 | 3418 | ||
| 3419 | DEFVAR_BOOL ("load-dangerous-libraries", &load_dangerous_libraries, | ||
| 3420 | "Non-nil means load dangerous compiled Lisp files.\n\ | ||
| 3421 | Some versions of XEmacs use different byte codes than Emacs. These\n\ | ||
| 3422 | incompatible byte codes can make Emacs crash when it tries to execute\n\ | ||
| 3423 | them."); | ||
| 3424 | load_dangerous_libraries = 0; | ||
| 3425 | |||
| 3426 | Vbytecomp_version_regexp = build_string ("^;;;.in Emacs version"); | ||
| 3427 | staticpro (&Vbytecomp_version_regexp); | ||
| 3428 | |||
| 3354 | /* Vsource_directory was initialized in init_lread. */ | 3429 | /* Vsource_directory was initialized in init_lread. */ |
| 3355 | 3430 | ||
| 3356 | load_descriptor_list = Qnil; | 3431 | load_descriptor_list = Qnil; |