unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Bug when compiling elc code?
@ 2007-08-08 10:29 Hadron
  2007-08-08 11:37 ` Johan Bockgård
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Hadron @ 2007-08-08 10:29 UTC (permalink / raw)
  To: help-gnu-emacs


I recently added this bit of lisp to my .emacs in order to automatically
byte compile any el files I saved

,----
| (add-hook 'emacs-lisp-mode-hook
|           '(lambda ()
|              (make-local-hook 'after-save-hook)
|              (add-hook 'after-save-hook
|                        '(lambda ()
|                           (byte-compile-file buffer-file-name))
|                        nil t)))
`----

I have my gnus specifics such as smtp server names and passwords in a
"personal.el" file which is obviously not readable by anyone but my own
login and root.

Unfortunately byte-compile-file produced the following:

-rw------- 1 hadron hadron 4961 2007-08-08 12:19 personal.el
-rw-r--r-- 1 hadron hadron 3795 2007-08-08 12:19 personal.elc

In other words a readable by anyone elc file.

I just checked - I can load up the elc file and see all my passwords.

Bug or feature? Seems like a nasty bug to me.

Which leads on to the next question, is there something I can put into a
file to stop it compiling into an elc using this hook?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
  2007-08-08 10:29 Bug when compiling elc code? Hadron
@ 2007-08-08 11:37 ` Johan Bockgård
  2007-08-08 12:17 ` Sven Joachim
       [not found] ` <mailman.4528.1186577289.32220.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 9+ messages in thread
From: Johan Bockgård @ 2007-08-08 11:37 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron <hadronquark@googlemail.com> writes:

> Which leads on to the next question, is there something I can put into
> a file to stop it compiling into an elc using this hook?

(info "(elisp)Byte Compilation")

   If you do not want a Lisp file to be compiled, ever, put a file-local
   variable binding for `no-byte-compile' into it, like this:

       ;; -*-no-byte-compile: t; -*-

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
  2007-08-08 10:29 Bug when compiling elc code? Hadron
  2007-08-08 11:37 ` Johan Bockgård
@ 2007-08-08 12:17 ` Sven Joachim
       [not found]   ` <d3abt22nwk.fsf@googlemail.com>
       [not found] ` <mailman.4528.1186577289.32220.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 9+ messages in thread
From: Sven Joachim @ 2007-08-08 12:17 UTC (permalink / raw)
  To: Hadron; +Cc: help-gnu-emacs

Hadron <hadronquark@googlemail.com> writes:

> I recently added this bit of lisp to my .emacs in order to automatically
> byte compile any el files I saved
>
> ,----
> | (add-hook 'emacs-lisp-mode-hook
> |           '(lambda ()
> |              (make-local-hook 'after-save-hook)
> |              (add-hook 'after-save-hook
> |                        '(lambda ()
> |                           (byte-compile-file buffer-file-name))
> |                        nil t)))
> `----
>
> I have my gnus specifics such as smtp server names and passwords in a
> "personal.el" file which is obviously not readable by anyone but my own
> login and root.
>
> Unfortunately byte-compile-file produced the following:
>
> -rw------- 1 hadron hadron 4961 2007-08-08 12:19 personal.el
> -rw-r--r-- 1 hadron hadron 3795 2007-08-08 12:19 personal.elc
>
> In other words a readable by anyone elc file.
>
> I just checked - I can load up the elc file and see all my passwords.
>
> Bug or feature? Seems like a nasty bug to me.

No, not really.  If personal.elc does not exist, Emacs creates it
according to your current umask, like any other file.  You can change
this default with the function set-default-file-modes, please try the
following: 

(add-hook 'emacs-lisp-mode-hook
	  '(lambda ()
	     (make-local-hook 'after-save-hook)
	     (add-hook 'after-save-hook
		       '(lambda ()
			  (let ((old-mode (default-file-modes)))
			    (set-default-file-modes (file-modes buffer-file-name))
			    (byte-compile-file buffer-file-name)
			    (set-default-file-modes old-mode)))
		       nil t)))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
       [not found] ` <mailman.4528.1186577289.32220.help-gnu-emacs@gnu.org>
@ 2007-08-08 13:18   ` Johan Bockgård
  2007-08-08 14:59     ` Sven Joachim
       [not found]     ` <mailman.4534.1186585008.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Johan Bockgård @ 2007-08-08 13:18 UTC (permalink / raw)
  To: help-gnu-emacs

Sven Joachim <svenjoac@gmx.de> writes:

>     (let ((old-mode (default-file-modes)))
>       (set-default-file-modes (file-modes buffer-file-name))
>       (byte-compile-file buffer-file-name)
>       (set-default-file-modes old-mode)))

You should use `unwind-protect' here.

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
  2007-08-08 13:18   ` Johan Bockgård
@ 2007-08-08 14:59     ` Sven Joachim
       [not found]     ` <mailman.4534.1186585008.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Sven Joachim @ 2007-08-08 14:59 UTC (permalink / raw)
  To: help-gnu-emacs

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

> Sven Joachim <svenjoac@gmx.de> writes:
>
>>     (let ((old-mode (default-file-modes)))
>>       (set-default-file-modes (file-modes buffer-file-name))
>>       (byte-compile-file buffer-file-name)
>>       (set-default-file-modes old-mode)))
>
> You should use `unwind-protect' here.

Right, thanks.  Is the following okay?

(add-hook 'emacs-lisp-mode-hook
	  '(lambda ()
	     (make-local-hook 'after-save-hook)
	     (add-hook 'after-save-hook
		       '(lambda ()
			  (let ((old-mode (default-file-modes)))
			    (unwind-protect
				(progn
				  (set-default-file-modes (file-modes buffer-file-name))
				  (byte-compile-file buffer-file-name))
			      (set-default-file-modes old-mode))))
		       nil t)))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
       [not found]     ` <mailman.4534.1186585008.32220.help-gnu-emacs@gnu.org>
@ 2007-08-08 16:09       ` weber
  2007-08-08 16:57         ` Sven Joachim
  0 siblings, 1 reply; 9+ messages in thread
From: weber @ 2007-08-08 16:09 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 1212 bytes --]

On 8 ago, 11:59, Sven Joachim <svenj...@gmx.de> wrote:
> bojohan+n...@dd.chalmers.se (Johan Bockgård) writes:
> > Sven Joachim <svenj...@gmx.de> writes:
>
> >>     (let ((old-mode (default-file-modes)))
> >>       (set-default-file-modes (file-modes buffer-file-name))
> >>       (byte-compile-file buffer-file-name)
> >>       (set-default-file-modes old-mode)))
>
> > You should use `unwind-protect' here.
>
> Right, thanks.  Is the following okay?
>
> (add-hook 'emacs-lisp-mode-hook
>           '(lambda ()
>              (make-local-hook 'after-save-hook)
>              (add-hook 'after-save-hook
>                        '(lambda ()
>                           (let ((old-mode (default-file-modes)))
>                             (unwind-protect
>                                 (progn
>                                   (set-default-file-modes (file-modes buffer-file-name))
>                                   (byte-compile-file buffer-file-name))
>                               (set-default-file-modes old-mode))))
>                        nil t)))

Btw, is keeping a password inside a .elc file and deleting the
original .el a semi-safe way to hide your personal info ?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
       [not found]   ` <d3abt22nwk.fsf@googlemail.com>
@ 2007-08-08 16:45     ` Sven Joachim
       [not found]     ` <mailman.4536.1186591345.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Sven Joachim @ 2007-08-08 16:45 UTC (permalink / raw)
  To: Hadron; +Cc: help-gnu-emacs

[Please keep this topic on-list. Thanks.]

Hadron <hadronquark@googlemail.com> writes:

> The problem is that even if personal.elc exists in 600 mode, then a
> recompile puts it back to 644. This is surely a bug?

Maybe, but other compilers (gcc, for instant) behave similarly: they
remove the target before they write to it.  And Emacs has a good
reason to do this, as can be seen from this comment in the
byte-compile-file function in bytecomp.el:

,----
| 		  (when (file-exists-p target-file)
| 		    ;; Remove the target before writing it, so that any
| 		    ;; hard-links continue to point to the old file (this makes
| 		    ;; it possible for installed files to share disk space with
| 		    ;; the build tree, without causing problems when emacs-lisp
| 		    ;; files in the build tree are recompiled).
| 		    (delete-file target-file))
| 		  (write-region (point-min) (point-max) target-file))
`----

Regards,
        Sven

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
  2007-08-08 16:09       ` weber
@ 2007-08-08 16:57         ` Sven Joachim
  0 siblings, 0 replies; 9+ messages in thread
From: Sven Joachim @ 2007-08-08 16:57 UTC (permalink / raw)
  To: help-gnu-emacs

weber <hugows@gmail.com> writes:

> Btw, is keeping a password inside a .elc file and deleting the
> original .el a semi-safe way to hide your personal info ?

No, the password is still stored as clear text and the .elc file can
be disassembled:

  (info "(elisp)Disassembly")

Cheers,
       Sven

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Bug when compiling elc code?
       [not found]     ` <mailman.4536.1186591345.32220.help-gnu-emacs@gnu.org>
@ 2007-08-08 17:21       ` Hadron
  0 siblings, 0 replies; 9+ messages in thread
From: Hadron @ 2007-08-08 17:21 UTC (permalink / raw)
  To: help-gnu-emacs

Sven Joachim <svenjoac@gmx.de> writes:

> [Please keep this topic on-list. Thanks.]

Better not to copy on email then - I thought I had replied to the
group. Sorry, about that.

>
> Hadron <hadronquark@googlemail.com> writes:
>
>> The problem is that even if personal.elc exists in 600 mode, then a
>> recompile puts it back to 644. This is surely a bug?
>
> Maybe, but other compilers (gcc, for instant) behave similarly: they
> remove the target before they write to it.  And Emacs has a good
> reason to do this, as can be seen from this comment in the
> byte-compile-file function in bytecomp.el:

As I said in private email, this is not the same thing. passwords etc
tend not to be hard coded into C/C++ files - they are in external
resource/config files which can be cleartext but are hidden by the linux file
permissions in many cases (or even gnupg encrypted).

At the very least I would think that the compile should maintain the
read/access modes of the original .el file.

Either that or something as happened to me might well happen to others
without them realising it. I can see no drawback to keeping the mode of
the elc file as the same as that of the source. Or?

>
> ,----
> | 		  (when (file-exists-p target-file)
> | 		    ;; Remove the target before writing it, so that any
> | 		    ;; hard-links continue to point to the old file (this makes
> | 		    ;; it possible for installed files to share disk space with
> | 		    ;; the build tree, without causing problems when emacs-lisp
> | 		    ;; files in the build tree are recompiled).
> | 		    (delete-file target-file))
> | 		  (write-region (point-min) (point-max) target-file))
> `----
>
> Regards,
>         Sven
>
>

-- 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-08-08 17:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-08 10:29 Bug when compiling elc code? Hadron
2007-08-08 11:37 ` Johan Bockgård
2007-08-08 12:17 ` Sven Joachim
     [not found]   ` <d3abt22nwk.fsf@googlemail.com>
2007-08-08 16:45     ` Sven Joachim
     [not found]     ` <mailman.4536.1186591345.32220.help-gnu-emacs@gnu.org>
2007-08-08 17:21       ` Hadron
     [not found] ` <mailman.4528.1186577289.32220.help-gnu-emacs@gnu.org>
2007-08-08 13:18   ` Johan Bockgård
2007-08-08 14:59     ` Sven Joachim
     [not found]     ` <mailman.4534.1186585008.32220.help-gnu-emacs@gnu.org>
2007-08-08 16:09       ` weber
2007-08-08 16:57         ` Sven Joachim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).