From mboxrd@z Thu Jan 1 00:00:00 1970 Path: quimby.gnus.org!not-for-mail From: Colin Walters Newsgroups: gmane.emacs.devel Subject: Re: many packages write to `temporary-file-directory' insecurely Date: 06 Mar 2002 02:35:26 -0500 Message-ID: <1015400126.18074.0.camel@space-ghost> References: <1014945351.23435.102.camel@space-ghost> <1015103550.7365.17.camel@space-ghost> <200203031718.g23HIKt23295@rum.cs.yale.edu> <200203042340.g24NexL00497@aztec.santafe.edu> <200203051520.g25FKbw01899@rum.cs.yale.edu> <1015389617.25883.37.camel@space-ghost> NNTP-Posting-Host: quimby2.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-9PosoXpR95nowbbv2wiE" X-Trace: quimby2.netfonds.no 1015400778 3739 195.204.10.66 (6 Mar 2002 07:46:18 GMT) X-Complaints-To: usenet@quimby2.netfonds.no NNTP-Posting-Date: 6 Mar 2002 07:46:18 GMT Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby2.netfonds.no with esmtp (Exim 3.12 #1 (Debian)) id 16iW7u-0000yD-00 for ; Wed, 06 Mar 2002 08:46:18 +0100 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.33 #1 (Debian)) id 16iW0v-0008CE-00; Wed, 06 Mar 2002 02:39:05 -0500 Original-Received: from monk.debian.net ([216.185.54.61] helo=monk.verbum.org) by fencepost.gnu.org with esmtp (Exim 3.33 #1 (Debian)) id 16iVy4-00085e-00 for ; Wed, 06 Mar 2002 02:36:08 -0500 Original-Received: from space-ghost.verbum.private (dhcp024-208-188-193.columbus.rr.com [24.208.188.193]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (Client CN "space-ghost.verbum.org", Issuer "monk.verbum.org" (verified OK)) by monk.verbum.org (Postfix (Debian/GNU)) with ESMTP id C5EA17400083 for ; Wed, 6 Mar 2002 02:35:57 -0500 (EST) Original-Received: by space-ghost.verbum.private (Postfix (Debian/GNU), from userid 1000) id DB1548067D2; Wed, 6 Mar 2002 02:35:26 -0500 (EST) Original-To: emacs-devel@gnu.org In-Reply-To: <1015389617.25883.37.camel@space-ghost> X-Mailer: Evolution/1.0 (Preview Release) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.5 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: quimby.gnus.org gmane.emacs.devel:1759 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:1759 --=-9PosoXpR95nowbbv2wiE Content-Type: text/plain Content-Transfer-Encoding: 7bit How about the following? One issue still to consider is whether or not we should default to writing game state in ~/.emacs.d, or in `temporary-file-directory'. Any opinions? --=-9PosoXpR95nowbbv2wiE Content-Disposition: attachment; filename=gamestate.patch Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Index: src/filelock.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/src/filelock.c,v retrieving revision 1.96 diff -u -r1.96 filelock.c --- src/filelock.c 6 Feb 2002 15:44:28 -0000 1.96 +++ src/filelock.c 6 Mar 2002 07:34:59 -0000 @@ -762,6 +762,7 @@ { DEFVAR_LISP ("temporary-file-directory", &Vtemporary_file_directory, doc: /* The directory for writing temporary files. */); + /* We initialize this more intelligently later in startup.el */ Vtemporary_file_directory =3D Qnil; =20 defsubr (&Sunlock_buffer); Index: src/callproc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/src/callproc.c,v retrieving revision 1.182 diff -u -r1.182 callproc.c --- src/callproc.c 4 Mar 2002 23:41:00 -0000 1.182 +++ src/callproc.c 6 Mar 2002 07:35:00 -0000 @@ -104,7 +104,7 @@ #endif =20 Lisp_Object Vexec_path, Vexec_directory, Vexec_suffixes; -Lisp_Object Vdata_directory, Vdoc_directory; +Lisp_Object Vdata_directory, Vdoc_directory, Vgame_state_directory; Lisp_Object Vconfigure_info_directory; Lisp_Object Vtemp_file_name_pattern; =20 @@ -1534,6 +1534,9 @@ } } =20 + /* We initialize this more intelligently later in startup.el */ + Vgame_state_directory =3D Qnil; + =20 #ifndef CANNOT_DUMP if (initialized) #endif @@ -1614,6 +1617,11 @@ DEFVAR_LISP ("data-directory", &Vdata_directory, doc: /* Directory of machine-independent files that come with GNU = Emacs. These are files intended for Emacs to use while it runs. */); + + DEFVAR_LISP ("game-state-directory", &Vgame_state_directory, + doc: /* Directory of high-score and other state files for games. +Depending on your system setup, this may or may not default to a +shared directory. */); =20 DEFVAR_LISP ("doc-directory", &Vdoc_directory, doc: /* Directory containing the DOC file that comes with GNU Emac= s. Index: lisp/startup.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/startup.el,v retrieving revision 1.290 diff -u -r1.290 startup.el --- lisp/startup.el 6 Feb 2002 14:59:10 -0000 1.290 +++ lisp/startup.el 6 Mar 2002 07:35:01 -0000 @@ -653,6 +653,19 @@ (if (eq system-type 'ms-dos) (getenv "TMPDIR"))) =20 + (unless game-state-directory + (setq game-state-directory + (let (ret + choice + (choices (list "/var/games/emacs" "/var/games" + temporary-file-directory))) + (while (and (not ret) (setq choice (car choices))) + (when (and (eq (car (file-attributes choice)) t) + (file-writable-p choice)) + (setq ret choice)) + (setq choices (cdr choices))) + ret))) + ;; See if we should import version-control from the environment variable= . (let ((vc (getenv "VERSION_CONTROL"))) (cond ((eq vc nil)) ;don't do anything if not set Index: lisp/play/gamegrid.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/play/gamegrid.el,v retrieving revision 1.5 diff -u -r1.5 gamegrid.el --- lisp/play/gamegrid.el 3 Mar 2002 14:13:53 -0000 1.5 +++ lisp/play/gamegrid.el 6 Mar 2002 07:35:02 -0000 @@ -404,27 +404,39 @@ =20 ;; ;;;;;;;;;;;;;;; high score functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;;;; =20 -(defun gamegrid-add-score (file score) - "Add the current score to the high score file." +(defun gamegrid-add-score (filename score &optional directory) + "Add SCORE to the high score file named FILENAME. +If DIRECTORY is non-nil, then place the high-score file in that +directory. Otherwise, place the high score file in +`game-state-directory'. +Note that there is no attempt made to guarantee that all scores will +be written to the score file if multiple Emacs users are writing to +the score file using this function at the same time." (save-excursion - (find-file-other-window file) - (setq buffer-read-only nil) - (goto-char (point-max)) - (insert (format "%05d\t%s\t%s <%s>\n" - score - (current-time-string) - (user-full-name) - (cond ((fboundp 'user-mail-address) - (user-mail-address)) - ((boundp 'user-mail-address) - user-mail-address) - (t "")))) - (sort-numeric-fields 1 (point-min) (point-max)) - (reverse-region (point-min) (point-max)) - (goto-line (1+ gamegrid-score-file-length)) - (delete-region (point) (point-max)) - (setq buffer-read-only t) - (save-buffer))) + (let* (buf + (file (expand-file-name filename (or directory game-state-directory))) + (tempfile (make-temp-file file))) + (while (setq buf (find-buffer-visiting file)) + (kill-buffer buf)) + (with-temp-file tempfile + (when (file-exists-p file) + (insert-file-contents file nil nil nil t)) + (goto-char (point-max)) + (insert (format "%05d\t%s\t%s <%s>\n" + score + (current-time-string) + (user-full-name) + (cond ((fboundp 'user-mail-address) + (user-mail-address)) + ((boundp 'user-mail-address) + user-mail-address) + (t "")))) + (sort-numeric-fields 1 (point-min) (point-max)) + (reverse-region (point-min) (point-max)) + (goto-line (1+ gamegrid-score-file-length)) + (delete-region (point) (point-max))) + (rename-file tempfile file t) + (find-file-other-window file)))) =20 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;;;; =20 Index: lisp/play/snake.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/play/snake.el,v retrieving revision 1.8 diff -u -r1.8 snake.el --- lisp/play/snake.el 3 Mar 2002 16:09:28 -0000 1.8 +++ lisp/play/snake.el 6 Mar 2002 07:35:02 -0000 @@ -82,10 +82,7 @@ (defvar snake-score-y snake-height "Y position of score.") =20 -;; It is not safe to put this in /tmp. -;; Someone could make a symlink in /tmp -;; pointing to a file you don't want to clobber. -(defvar snake-score-file "~/.snake-scores" +(defvar snake-score-file "snake-scores" "File for holding high scores.") =20 ;; ;;;;;;;;;;;;; display options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;;;; Index: lisp/play/tetris.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/play/tetris.el,v retrieving revision 1.7 diff -u -r1.7 tetris.el --- lisp/play/tetris.el 3 Mar 2002 16:09:28 -0000 1.7 +++ lisp/play/tetris.el 6 Mar 2002 07:35:02 -0000 @@ -150,10 +150,7 @@ (defvar tetris-score-y (+ tetris-next-y 6) "Y position of score.") =20 -;; It is not safe to put this in /tmp. -;; Someone could make a symlink in /tmp -;; pointing to a file you don't want to clobber. -(defvar tetris-score-file "~/.tetris-scores" +(defvar tetris-score-file "tetris-scores" ;; anybody with a well-connected server want to host this? ;(defvar tetris-score-file "/anonymous@ftp.pgt.com:/pub/cgw/tetris-scores" "File for holding high scores.") --=-9PosoXpR95nowbbv2wiE-- _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel